我正在使用nodejs和一个名为oauth的npm包来与twitter的搜索api通信。然而,出于某种原因,twitter正在返回一个空的状态数组,没有任何错误…更令人困惑的是,使用一个类似postman的工具,使用完全相同的请求和键返回tweets列表?这没道理!这是我的请求:
网址:https://api.twitter.com/1.1/search/tweets.json?count=100&q=hello&since_id=577103514154893312&max_id=577103544903462913
这是我的代码:

    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();

console.log(message)返回:
{
    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'
    }
}

你知道怎么回事吗?为什么status数组在我的代码中是空的,但在postman中却充满了tweets?

最佳答案

这个问题在twittercommunity.com上有描述。
相应地,用户rchoi(twitter工作人员)的回答是:
“关于web和api搜索,我们知道这两种搜索目前返回的结果不同。我们对网络搜索进行了升级。这些没有时间表
将对我们系统的其他部分进行更改。”
尝试使用
https://dev.twitter.com/rest/reference/get/statuses/mentions_timeline
https://dev.twitter.com/rest/reference/get/statuses/user_timeline
如果使用api搜索功能得到空结果。
请按此链接
https://twittercommunity.com/t/search-tweets-api-returned-empty-statuses-result-for-some-queries/12257/6

关于json - Twitter搜索API没有返回任何推文?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/29062363/

10-11 22:14
查看更多