Search API returning no tweets!


#1

Hello,

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) {
                message = {};
            }

            console.log("Message", 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:”, 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 tweet in Postman?


#2

Hey, Jamesking56

Could you explicitly write the order of search operators you use?

I stumbled upon the same issue as yours Order dependent Search API operators. Possible bug? . I have no statuses, but the count is > 0


#3

Hey,

You can see in my post above the exact URL and order:

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


#4

Here again. Sorry for the delay.

Test your parameters q=hello&count=100&since_id=577103514154893312&since_id=577103514154893312&max_id=5771035449034629132

In https://dev.twitter.com/rest/tools/console

I tried your parameters against tweets.json and I get statuses as seen in https://snap.apigee.com/1FqJiPd .

The problem is either with the code your provided or the NPM OAuth library, but it’s not a problem in the Twitter Search API at least.