「TwythonRateLimitError」が発生しました。アカウントを台無しにしないようにしたいと考えています。Twitter API を使用するのは初めてです。クエリの制限を超えていないことを確認するにはどうすればよいですか? 1 時間あたり 150 クエリであると読みましたが、そうするとどうなりますか? 私のコードでこれの危険にさらされていますか、それとも特定のコマンドのみですか?
私はアプリを構築しているのではなく、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