简体   繁体   中英

Twitter search API returns no tweets?

I'm using NodeJS and an npm package called oauth to communicate with Twitter's search API. For some reason however, twitter is returning to me an empty array of statuses without any error... What is even more confusing is the fact that using a tool like Postman with the exact same request and keys returns the list of tweets? It makes no sense! Here is my request:

URL: https://api.twitter.com/1.1/search/tweets.json?count=100&q=hello&since_id=577103514154893312&max_id=577103544903462913

Here is my code:

    var twitter_auth = new OAuth(
        "https://api.twitter.com/oauth/request_token",
        "https://api.twitter.com/oauth/access_token",
        config.consumer_key,
        config.consumer_secret,
        "1.0A",
        null,
        "HMAC-SHA1"
    );

    var request = twitter_auth.get(
        "https://api.twitter.com/1.1/search/tweets.json" + url,
        config.access_token,
        config.access_token_secret
    );

    var chunk = "", message = "", that = this;
    request.on("response", function(response){
        response.setEncoding("utf8");
        response.on("data", function(data){
            chunk += data;

            try {
                message = JSON.parse(chunk);
            } catch(e) {
                return;
            }

            console.log(message);

            if(message.statuses)
            {
                for(var i = 0; i < message.statuses.length; i++)
                {
                    var tweet = message.statuses[i];
                    that.termData[term.name].push(tweet);
                }
                if(message.search_metadata.next_results)
                {
                    that.openRequests.push(that.createNewSearch(message.search_metadata.next_results, term));
                }
                else
                {
                    that.termCompleted(term);
                }
            }
            else if(message)
            {
                console.log("Response does not appear to be valid.");
            }
        });
        response.on("end", function(){
            console.log("Search API End");
        });
        response.on("error", function(err){
            console.log("Search API Error", err);
        });
    });

    request.end();

The console.log(message) is returning this:

{
    statuses: [],
    search_metadata: {
        completed_in: 0.007,
        max_id: 577103544903462900,
        max_id_str: '577103544903462913',
        query: 'hello',
        refresh_url: '?since_id=577103544903462913&q=hello&include_entities=1',
        count: 100,
        since_id: 577103514154893300,
        since_id_str: '577103514154893312'
    }
}

Any ideas what is going on? Why is the statuses array empty in my code but full of tweets in Postman?

This issue was described at twittercommunity.com .

Accordingly answer of user rchoi (Twitter Staff):

"Regarding web vs. API search, we're aware that the two return different results at the moment. We made upgrades to the web search. There is no timeline for those changes to be brought to other parts of our system."

Try to use https://dev.twitter.com/rest/reference/get/statuses/mentions_timeline https://dev.twitter.com/rest/reference/get/statuses/user_timeline if you get empty result with api search functionality.

Please follow this link https://twittercommunity.com/t/search-tweets-api-returned-empty-statuses-result-for-some-queries/12257/6

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM