我得到了一个'TwythonRateLimitError‘,并希望确保我没有搞砸我的帐户。我刚开始使用Twitter。我如何检查以确保我没有超过我的查询限制?我读到每小时有150个查询.如果我这么做了怎么办?在我的代码中,我是否面临这样的风险?还是只针对特定的命令?
我不是在建立一个应用程序,我只是想得到一个特定的例子推特(随机的一组类似的用户群(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发布于 2013-11-05 03:26:00
https://stackoverflow.com/questions/19780666
复制相似问题