Twitter 搜索 API 不返回任何推文



我正在使用NodeJS和一个名为oauth的npm包与Twitter的搜索API进行通信。然而,出于某种原因,推特向我返回了一个空的状态数组,没有任何错误......更令人困惑的是,使用像 Postman 这样具有完全相同的请求和密钥的工具会返回推文列表?没道理!这是我的要求:

网址: 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'
    }
}

知道发生了什么吗?为什么状态数组在我的代码中为空,但在邮递员中充满了推文?

此问题已在 twittercommunity.com 中描述。

因此,用户rchoi(推特工作人员)的回答:

"关于Web与API搜索,我们知道两者目前返回不同的结果。我们对网络搜索进行了升级。这些没有时间表将对我们系统的其他部分进行更改。

尝试使用https://dev.twitter.com/rest/reference/get/statuses/mentions_timelinehttps://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

相关内容

最新更新