N
N
Nikita Shvetsov2015-08-28 16:37:31
PHP
Nikita Shvetsov, 2015-08-28 16:37:31

Problem with searching multiple words via Twitter API (PHP)?

Good evening, I'm using the following code to search twitter:

<?php
require("twitteroauth/autoload.php"); 
use Abraham\TwitterOAuth\TwitterOAuth;
 
define('CONSUMER_KEY', '-'); /
define('CONSUMER_SECRET', '-');
define('ACCESS_TOKEN', '-');
define('ACCESS_TOKEN_SECRET', '-');
 
function search(array $query)
{
  $toa = new TwitterOAuth(CONSUMER_KEY, CONSUMER_SECRET, ACCESS_TOKEN, ACCESS_TOKEN_SECRET);
  return $toa->get('search/tweets', $query);
}
 
$query = [
  "q" => "Путин+заявление",
];
  
$results = search($query);
if ($results->statuses == NULL){
  echo "<b> Совпадений по слову _" . $query["q"] . "_ не найдено </b> <br>";	
 } else {
foreach ($results->statuses as $result) {
  echo $result->user->screen_name . ": " . $result->text . "<br>";
}
}
?>

This code works, but if q sets the text " Putin+statement+Kremlin ", then it doesn't find anything (of course it finds it in the search through the site itself). At the same time, the text in three words (for example, " Moscow + river + burns ") remains working. I can't figure out what the problem is. I would be extremely grateful for a hint.
UPD
But when requesting "moscow+river+putin", only one tweet comes in response (no matter how many are specified by the parameter), although again, there are many more of them in the search results on the site itself. Well, what could it be?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
N
Nikita Shvetsov, 2015-08-28
@Cloud_thaves

That's it, I read the manual more carefully and saw that, unfortunately:
"Keep in mind that the search index has a 7-day limit. In other words, no tweets will be found for a date older than one week."

V
Vlad Pasechnik, 2015-08-28
@jumper423

It's over, maybe this is nonsense, but try to lowercase the string

mb_strtolower ("Putin+statement+Kremlin")

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question