Closed gretarmagg closed 9 years ago
Could you paste the code you are using?
$url = 'https://api.twitter.com/1.1/search/tweets.json';
$getfield = '?q=%23mitthverfi&result_type=mixed&count=5';
$requestMethod = 'GET';
Here is the whole code
require_once('TwitterAPIExchange.php');
/** Set access tokens here - see: https://dev.twitter.com/apps/ **/
$settings = array(
'oauth_access_token' => "#####",
'oauth_access_token_secret' => "#####",
'consumer_key' => "#####",
'consumer_secret' => "#####"
);
$url = 'https://api.twitter.com/1.1/search/tweets.json';
$getfield = '?q=%23mitthverfi&count=5';
$requestMethod = 'GET';
$twitter = new TwitterAPIExchange($settings);
$api_response = $twitter ->setGetfield($getfield)
->buildOauth($url, $requestMethod)
->performRequest();
$response = json_decode($api_response);
if (!empty($response)) :
foreach ($response->statuses as $tweet) :
$datetime = $tweet->created_at;
$date = date('M d, Y', strtotime($datetime));
$time = date('g:ia', strtotime($datetime));
$tweet_text = $tweet->text;
// check if any entites exist and if so, replace then with hyperlinked versions
foreach ($tweet->entities->urls as $url) {
$find = $url->url;
$replace = '<a href="'.$find.'">'.$find.'</a>';
$tweet_text = str_replace($find,$replace,$tweet_text);
}
foreach ($tweet->entities->hashtags as $hashtag) {
$find = '#'.$hashtag->text;
$replace = '<a href="http://twitter.com/#!/search/%23'.$hashtag->text.'">'.$find.'</a>';
$tweet_text = str_replace($find,$replace,$tweet_text);
}
foreach ($tweet->entities->user_mentions as $user_mention) {
$find = "@".$user_mention->screen_name;
$replace = '<a href="http://twitter.com/'.$user_mention->screen_name.'">'.$find.'</a>';
$tweet_text = str_ireplace($find,$replace,$tweet_text);
}
echo '<div class="col_twitter">
<div class="avatar_col"><img src="'."{$tweet->user->profile_image_url_https}".'" width="21" height="21"></div>
<div class="twitter_text">
<div class="info_text"><strong>';
echo "{$tweet->user->name}".'</strong> @'."{$tweet->user->screen_name}".'</div>';
echo '<p>'.$tweet_text.'</p></div>';
echo '<div class="twitter_links"><a href="https://twitter.com/intent/tweet?in_reply_to='."{$tweet->id}".'" target="_blank">Reply</a> <a href="https://twitter.com/intent/retweet?tweet_id='."{$tweet->id}".'" target="_blank">Retweet</a> <a href="https://twitter.com/intent/favorite?tweet_id='."{$tweet->id}".'" target="_blank">Favorite</a></div>';
echo '</div>';
endforeach;
endif;
Could you try changing your "%23" to a #
character and try again (just interested if this works without having to encode the has anyway)? I'll take a look at this in a little while.
I have tried that also but that did not change anything.
Also, the API docs show you can use &result_type=recent
to fetch the most recent ones. I'll take a look at the count soon, but the twitter API doesn't always return the exact tweets that they have - it's not always up-to-date - you can view this in the FAQ here:
Why are the Tweets I'm looking for not in Twitter Search, the Search API, or Search widgets?
Twitter's search is optimized to serve relevant tweets to end-users in response to direct, non-recurring queries such as #hashtags, URLs, domains, and keywords. The Search API (which also powers Twitter's search widget) is an interface to this search engine. Our search service is not meant to be an exhaustive archive of public tweets and not all tweets are indexed or returned. Some results are refined to better combat spam and increase relevance. Due to capacity constraints, the index currently only covers about a week's worth of tweets.
The user timeline API is the definitive source of tweets by a specific author. For a collection of recent Tweets by more than one user, consider creating a Twitter List and leveraging the list timeline. The Streaming API is often the best-fit choice when seeking completeness.
If the tweets you're looking for aren't available in search and you think they should be, consult this support topic for further instructions to contact @Support.
Yes I have tested the recent result_type also but to no avail. I know about this Twitter search thing, I have read the FAQ about this but it just baffles me why the count variable does not work when I want maby just one more Tweet (5 instead of 4) but when I ask for just 1 that works !
Hi again. Have you had the chance to look at this ?
Very old post, sorry... but this should be fixed :-)
Hi there. I'm using this API to fetch the latest tweets with the hashtag mitthverfi on a website. My website only displays the 4 latest tweets and when I set my getfield to count=10 or some higher number that does not change anything. When I try count=1 I only get one tweet.
How can I make this display all tweets or maby just more then the latest 4 ?