I have a Django app that needs to pull the follower_count
information from several twitter accounts. But I am running into some problems with the request limit. The app is not a twitter app so it does not have an account and does not user OAuth so white listing is not a possibility (if I am understanding whitelisting correctly). So I have a few questions:
1) Is there any way to get around this limit for non-twitter applications
2) Is the 150 limit a hard 1 hour? meaning if you hit the limit at 8am do you just wait until 9am regardless of requests made in the mean time or is the hour count reset each time a request is made after the initial 150?
3) I am currently using the following code to get my data:
for page in pages:
url = 'api.twitter.com/1/users/show/' + page.twitter_name + '.json'
target = urllib2.urlopen(url)
request = simplejson.loads(target.read())
# parse the request
Is this counting as one request per page object or is there anything I can do in this code to lessen the number of requests I am making per page?
4) Do I understand whitelisting correctly in that it is for twitter apps or should I look into whitelisting the various twitter accounts I am pulling informatio开发者_JAVA百科n from? ( I'm sure this information exists but all the links I could find regarding whitelisting were broken)
EDIT: I have now discovered that twitter no longer offers new whitelisting so disregard those elements of the question.
I'd say that for something like follower count, you don't need it to be right-to-the-second up-to-date. Since each load already generates a bunch of requests (getting multiple users data), you're better off sacrificing a little accuracy for less request generation. Store the counts you get in the page objects, perhaps along with a timestamp of when the last request was made, and then use the number from the model and only re-evaluate if it's been more than hour since the last check. The follower count is probably not changing that drastically anyways.
UPDATE: Any time you're working with a 3rd-party API, you should always be using mocks in development, especially with a rate limit involved. Just get the response once, save it, and then point your AJAX request to the saved copied during development.
Here's a good method to use to find the amount of 'remaining-hits' you have left:
http://api.twitter.com/1/account/rate_limit_status.json
It returns something like this, letting you know when you're allowed to make another request:
{
"remaining_hits": 150,
"reset_time_in_seconds": 1277234708,
"hourly_limit": 150,
"reset_time": "Tue Jun 22 19:25:08 +0000 2010"
}
POW
精彩评论