簡體   English   中英

Twython速率限制

[英]Twython rate limit

我收到了'TwythonRateLimitError',並希望確保我不會搞砸我的帳戶。 我是使用Twitter API的新手。 如何檢查以確保我沒有超出查詢限制? 我讀到這是每小時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

要查看您當前的費率限制狀態,請傳入您的應用令牌並發送GET請求

https://api.twitter.com/1.1/account/rate_limit_status.json

並查詢響應。

有關更多背景,請參閱此頁面

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM