Skip to content

Instantly share code, notes, and snippets.

@nhooey
Created October 21, 2013 20:38
Show Gist options
  • Save nhooey/7090571 to your computer and use it in GitHub Desktop.
Save nhooey/7090571 to your computer and use it in GitHub Desktop.
import sys
# Using OAuth1Session
from requests_oauthlib import OAuth1Session
if len(sys.argv) != 3:
print "Usage: %s <CLIENT_KEY> <CLIENT_SECRET>" % sys.argv[0]
sys.exit(1)
client_key = sys.argv[1]
client_secret = sys.argv[2]
request_token_url = 'https://api.twitter.com/oauth/request_token'
# Using OAuth1Session
oauth = OAuth1Session(client_key, client_secret=client_secret)
fetch_response = oauth.fetch_request_token(request_token_url)
print fetch_response
resource_owner_key = fetch_response.get('oauth_token')
resource_owner_secret = fetch_response.get('oauth_token_secret')
base_authorization_url = 'https://api.twitter.com/oauth/authorize'
# Using OAuth1Session
authorization_url = oauth.authorization_url(base_authorization_url)
print 'Please go here and authorize,', authorization_url
redirect_response = raw_input('Paste the full redirect URL here: ')
oauth_response = oauth.parse_authorization_response(redirect_response)
verifier = oauth_response.get('oauth_verifier')
print oauth_response
access_token_url = 'https://api.twitter.com/oauth/access_token'
# Using OAuth1Session
oauth = OAuth1Session(client_key,
client_secret=client_secret,
resource_owner_key=resource_owner_key,
resource_owner_secret=resource_owner_secret,
verifier=verifier)
oauth_tokens = oauth.fetch_access_token(access_token_url)
resource_owner_key = oauth_tokens.get('oauth_token')
resource_owner_secret = oauth_tokens.get('oauth_token_secret')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment