Giter Site home page Giter Site logo

Count does not work about twitter-api-php HOT 9 CLOSED

j7mbo avatar j7mbo commented on August 23, 2024
Count does not work

from twitter-api-php.

Comments (9)

J7mbo avatar J7mbo commented on August 23, 2024

Could you paste the code you are using?

from twitter-api-php.

gretarmagg avatar gretarmagg commented on August 23, 2024

$url = 'https://api.twitter.com/1.1/search/tweets.json';
$getfield = '?q=%23mitthverfi&result_type=mixed&count=5';
$requestMethod = 'GET';

from twitter-api-php.

gretarmagg avatar gretarmagg commented on August 23, 2024

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;                  

from twitter-api-php.

J7mbo avatar J7mbo commented on August 23, 2024

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.

from twitter-api-php.

gretarmagg avatar gretarmagg commented on August 23, 2024

I have tried that also but that did not change anything.

from twitter-api-php.

J7mbo avatar J7mbo commented on August 23, 2024

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.

from twitter-api-php.

gretarmagg avatar gretarmagg commented on August 23, 2024

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 !

from twitter-api-php.

gretarmagg avatar gretarmagg commented on August 23, 2024

Hi again. Have you had the chance to look at this ?

from twitter-api-php.

J7mbo avatar J7mbo commented on August 23, 2024

Very old post, sorry... but this should be fixed :-)

from twitter-api-php.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.