[英]Twython rate limit
I am getting a 'TwythonRateLimitError' and want to be sure that I don't screw up my account. 我收到了'TwythonRateLimitError',并希望确保我不会搞砸我的帐户。 I am new to working with the Twitter API.
我是使用Twitter API的新手。 How can I check to make sure that I am not going over my query limit?
如何检查以确保我没有超出查询限制? I read that it is 150 queries/hour... What happens if I do?
我读到这是每小时150次查询......如果我这样做会怎么样? Am I at a risk of this in my code or is it only for particular commands?
在我的代码中我是否有这种风险,或者仅针对特定命令?
I am not building an app, I am just trying to get a specific sample for twitter (random set of users with similar following bases (7500 to 10000 followers). My code so far is below. I will be saving the successful hits to a file but I am waiting to be sure that is necessary. 我不是在构建一个应用程序,我只是想获取一个特定的twitter样本(具有类似跟随基础的随机用户组(7500到10000个关注者)。到目前为止,我的代码在下面。我将保存成功的点击到文件,但我等待确保这是必要的。
from twython import Twython, TwythonError, TwythonRateLimitError
from random import randint
APP_KEY = 'redacted'
APP_SECRET = 'redacted'
ACCESS_TOKEN = 'redacted'
twitter = Twython(APP_KEY, APP_SECRET, oauth_version=2)
ACCESS_TOKEN = twitter.obtain_access_token()
twitter = Twython(APP_KEY,access_token=ACCESS_TOKEN)
print "hello twitterQuery\n"
count = 0
step = 0
isError = 0
try:
#new account i made today to set upper bound on userID
maxID = twitter.show_user(screen_name="query_test")['id']
except TwythonRateLimitError:
isError = 1
ids = [0,0,0,0,0,0,0,0,0,0]
if isError == 0 and step <= 150:
while count < 10:
step = step +1
randomID = randint(1,maxID)
isMissing = 0
print str(step) + " " + str(randomID)
try:
randomUserData = twitter.show_user(user_id=randomID)
except TwythonError:
isMissing = 1;
if isMissing == 0:
followers = randomUserData['followers_count']
if followers >= 7500 and followers <= 10000:
print "ID: " + str(randomID) +", followers: "+ str(followers)
ids[count] = randomID
count = count+1
print "\ndone"
for each id in ids:
print id
to see your current rate limit status, pass in your app token and send a GET request to 要查看您当前的费率限制状态,请传入您的应用令牌并发送GET请求
https://api.twitter.com/1.1/account/rate_limit_status.json https://api.twitter.com/1.1/account/rate_limit_status.json
and query the response. 并查询响应。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.