0
我收到'TwythonRateLimitError',並且想確保我不會搞砸我的帳戶。我是與Twitter API合作的新手。我如何檢查以確保我不會超出我的查詢限制?我讀到這是每小時150個查詢......如果我這樣做會怎樣?在我的代碼中,我是否有這種風險,還是隻針對特定的命令?我只是想要獲取twitter的具體示例(具有類似以下基礎(7500到10000追隨者)的隨機用戶集合。我的代碼至今爲止,我將保存這個應用程序成功命中一個文件,但我在等待,以確保是必要的。Twython限額
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
我看着這個顯示this page,我不知道如果我的理解。這是否意味着我可以查詢任何用戶多達15次?我在Twitter的開發者控制檯中運行了它,它從15到14,然後我運行我的應用程序並再次在控制檯中運行它,並期望它對每個查詢都爲-1,但實際上它根本沒有下降。這是因爲我只查詢一次我的開發用戶名?但是,如果我足夠運行它將引用「query_user」帳戶15次並用盡嘗試? –
它可能會緩存您的請求。 – Chamilyan