Skip to content

Instantly share code, notes, and snippets.

@danriti
Created January 24, 2012 03:16
Show Gist options
  • Save danriti/1667574 to your computer and use it in GitHub Desktop.
Save danriti/1667574 to your computer and use it in GitHub Desktop.
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