0

I am getting a 'TwythonRateLimitError' and want to be sure that I don't screw up my account. I am new to working with the Twitter API. How can I check to make sure that I am not going over my query limit? I read that it is 150 queries/hour... What happens if I do? Am I at a risk of this in my code or is it only for particular commands?

I am not building an app, I am just trying to get a specific sample for twitter (random set of users with similar following bases (7500 to 10000 followers). My code so far is below. I will be saving the successful hits to a file but I am waiting to be sure that is necessary.

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
Timo Loescher
  • 119
  • 1
  • 1
  • 16

1 Answers1

2

to see your current rate limit status, pass in your app token and send a GET request to

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

and query the response.

See this page for further context

Chamilyan
  • 9,347
  • 10
  • 38
  • 67
  • I looked into this and am not sure if I understand. Does that mean I can query any user up to 15 times? I ran this in the Twitter dev console and it went from 15 to 14, then I ran my application and ran it in the console again and expected it to -1 for each query but it didnt actually go down at all. Is this because I only queried my dev username once? But if I run it enough it will reference the "query_user" account 15 times and use up the attempts? – Timo Loescher Nov 05 '13 at 17:47
  • it's probably caching your requests. – Chamilyan Nov 05 '13 at 22:46