Twitter搜索限制从未如此严格

时间:2015-02-01 15:43:08

标签: python twitter twython

我知道Twitter搜索API有它自己的局限性并且返回的搜索结果要少得多,而不是实际的结果,但我正在搜索一个流行的标签,它只返回60个结果,这是完全不可接受的!

这是我使用twython模块的代码。

results = {}
last_id = None
count = 0
while(len(results.keys()) != min_count):
    if(last_id):
        tmp_results = self.api.search(q="#mentionsomeoneimportantforyou", count=100, max_id=last_id)
    else:
        tmp_results = self.api.search(q=#mentionsomeoneimportantforyou, count=100)
    count += len(tmp_results['statuses'])
    print("new len:  ", count)
    last_id = get_max_id(tmp_results)


def get_max_id(results):
    next_results_url_params = results['search_metadata']['next_results']
    next_max_id = next_results_url_params.split('max_id=')[1].split('&')[0]
    return next_max_id

这段代码有什么用吗?它不是,不是很多笑话中的60个?

2 个答案:

答案 0 :(得分:0)

twython docs建议不这样做,而是使用光标方法:

twitter = Twython(APP_KEY, APP_SECRET,
                  OAUTH_TOKEN, OAUTH_TOKEN_SECRET)

results = twitter.cursor(twitter.search, q='python')
count = 0
for result in results:
    print result['id_str']
    count += 1
print count

打印:

... many here ...
561918886380322816
561918859050229761
561919180480737282
561919151162130434
561919142450581504
561919113812246529
561919107134922753
561919103867559938
561919077481218049
561918994454556672
561918971755372546
561918962381127680
561918948288258048
561918911751655425
561918904126042112
561918886380322816
561918859050229761
645

答案 1 :(得分:0)

我想我找到了原因。根据{{​​3}},Twitter不会通过搜索API返回超过一周的推文。