Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Twitter API Access
#!/usr/bin/python
import simplejson as json
import oauth2 as oauth
# Create your consumer with the proper key/secret.
consumer = oauth.Consumer(key="YOUR_CONSUMER_KEY",
secret="YOUR_CONSUMER_SECRET")
# Create your token with the proper key/secret.
token = oauth.Token(key="YOUR_ACCESS_TOKEN",
secret="YOUR_ACCESS_TOKEN_SECRET")
# Request token URL for Twitter.
rate_limit_url = "http://api.twitter.com/1/account/rate_limit_status.json"
# Create our client.
client = oauth.Client(consumer, token)
# The OAuth Client request works just like httplib2 for the most part.
resp, content = client.request(rate_limit_url, "GET")
# Parse the JSON into a Python dictionary.
data = json.loads(content)
# Print hourly limits.
print "Hourly => %3d" % (data['hourly_limit'])
print "Remaining => %3d" % (data['remaining_hits'])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment