0

我收到一个“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
4

1 回答 1

2

要查看您当前的速率限制状态,请传入您的应用令牌并向其发送 GET 请求

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

并查询响应。

有关详细信息,请参阅页面

于 2013-11-05T03:26:00.303 回答