I’m doing research for college, where I need to do searches using the twitter API using the word “twitter” and some other keywords, to do some analysis. I did a simple application in php that returned me 1000 tweets from the word sought . However, the twitter API returns me tweets without the word ” twitter ” , I think this happens because the URLs ( links or images) of tweets that are replaced by “t.co” links.
My search code
<?php
require_once 'twitteroauth.php';
define('CONSUMER_KEY', 'aaaaaaaaa');
define('CONSUMER_SECRET', 'bbbbbbbbb');
define('ACCESS_TOKEN', 'cccccccccc');
define('ACCESS_TOKEN_SECRET', 'ddddddddddddd');
function search(array $query)
{
$toa = new TwitterOAuth(CONSUMER_KEY, CONSUMER_SECRET, ACCESS_TOKEN, ACCESS_TOKEN_SECRET);
return $toa->get('search/tweets', $query);
}
$max_id = "";
foreach (range(1, 10) as $i) {
$query = array(
"q" => $_POST['search'],
"count" => 100,
"result_type" => "mixed",
"max_id" => $max_id,
);
$results = search($query);
$a= $results->statuses;
foreach ($a as $result) {
echo $result->text .'<br>';
$max_id = $result->id_str;
}
}
die;