Skip to content

Instantly share code, notes, and snippets.

@denzilc
Created June 6, 2011 15:07
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save denzilc/1010430 to your computer and use it in GitHub Desktop.
Save denzilc/1010430 to your computer and use it in GitHub Desktop.
Twitter Oauth requests
'''
Created on Jun 6, 2011
@author: denzilc
'''
import oauth2 as oauth
import urlparse
import time
api_key = 'xxxxxxxxxxxxxxxxxxx'
CONSUMER_KEY = 'xxxxxxxxxxxxxxxxxxx'
CONSUMER_SECRET = 'xxxxxxxxxxxxxxxxxxx'
access_key = 'xxxxxxxxxxxxxxxxx'
access_secret_key = 'xxxxxxxxxxxxxxxxxxx'
consumer = oauth.Consumer(CONSUMER_KEY, CONSUMER_SECRET)
token = oauth.Token(access_key, access_secret_key)
client = oauth.Client(consumer, token)
url = 'http://api.twitter.com/1'
params = {'oauth_version': "1.0",
'oauth_nonce': oauth.generate_nonce(),
'oauth_timestamp': int(time.time()),
'oauth_token': access_key,
'oauth_consumer_key': consumer.key
}
req = oauth.Request(method="GET", url=url, parameters=params)
# Sign the request.
signature_method = oauth.SignatureMethod_HMAC_SHA1()
req.sign_request(signature_method, consumer, token)
### Make the auth request ###
test = 'http://api.twitter.com/1/account/rate_limit_status.json'
resp, content = client.request(test, "GET")
print resp
print content # prints 'ok''
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment