2014-10-20 50 views
2

我已经把一个小的推特工具放在一起,以拉取相关推文,以便在潜在语义分析中进行后续分析。具有讽刺意味的是,这一点(更复杂的一点)工作正常 - 它拉扯推文是这个问题。我正在使用下面的代码来设置它。我认为每个请求会推送200条推文,但它被阻止成15个推文块(因此200个商品“支付”我13个请求) - 这个技术上有效,但没有如预期的那样 - .items(200)我知道这是原始/默认的RPP变量(现在在Twitter文档中是'count'),但我已经在Cursor设置中尝试过了(rpp = 100,这是twitter文档中的最大值),并且它使没有不同。Tweepy限额/分页问题。

Tweepy/Cursor docs
The other nearest similar question isn't quite the same issue

感谢有任何的想法!我相信这是对设置的微调,但我已经尝试了页面和rpp上的各种设置,但无济于事。

auth = tweepy.OAuthHandler(apikey, apisecret) 
auth.set_access_token(access_token, access_token_secret_var) 
from tools import read_user, read_tweet 
from auth import basic 
api = tweepy.API(auth) 
current_results = [] 
from tweepy import Cursor 
for tweet in Cursor(api.search, 
         q=search_string, 
         result_type="recent", 
         include_entities=True, 
         lang="en").items(200): 
    current_user, created = read_user(tweet.author) 
    current_tweet, created = read_tweet(tweet, current_user) 
    current_results.append(tweet) 
print current_results 
+0

关于如何在某个瞬间获得特定hashtag的推文计数的任何想法?我正在使用'trends_place'来获取特定于某个国家的趋势。我需要更多的信息,其中包括特定hashtag的推文数量。 – 2015-04-21 05:02:56

回答

4

我最终完成了这项工作,得到了同事的一点帮助。 Afaict,在实际的API调用之后,rpp和items()调用即将到来。 Twitter documentation中的'count'选项是前面提到的RPP,在Tweepy 2.3.0中仍然被称为rpp,这似乎成了问题。

我最终做的是修改Tweepy代码 - 在api.py中,我将'count'添加到搜索绑定部分(在我安装的L643中,ymmv)。

""" search """ 
search = bind_api(
    path = '/search/tweets.json', 
    payload_type = 'search_results', 
    allowed_param = ['q', 'count', 'lang', 'locale', 'since_id', 'geocode', 'max_id', 'since', 'until', 'result_type', **'count**', 'include_entities', 'from', 'to', 'source'] 
) 

这让我调整上面的代码:

for tweet in Cursor(api.search, 
         q=search_string, 
         count=100, 
         result_type="recent", 
         include_entities=True, 
         lang="en").items(200): 

导致两个电话,而不是15;我已经在每次调用之后再次对此进行了检查

print api.rate_limit_status()["resources"] 

并且每次只将我的剩余搜索弃用为2。

+0

你应该接受这个答案。 – Luigi 2014-10-21 18:29:10

+0

是的,我必须再等12小时才能做到。 :) – Withnail 2014-10-22 07:19:07