I'm writing a code that uses Twitter API to get users' statuses, number of followers etc. I need to write a script that opens browser and asks users to sign in and let me get the authentication from them.
from requests_oauthlib import OAuth1Session import requests from requests_oauthlib import OAuth1 from urlparse import parse_qs client_key = "keykeykeykey" client_secret = "keykeykeykeykey" request_token_url = 'https://api.twitter.com/oauth/request_token' 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') oauth = OAuth1(client_key, client_secret=client_secret) r = requests.post(url=request_token_url, auth=oauth) #print(r.content) credentials = parse_qs(r.content) resource_owner_key = credentials.get('oauth_token')[0] resource_owner_secret = credentials.get('oauth_token_secret')[0] base_authorization_url = 'https://api.twitter.com/oauth/authorize' 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) #print(oauth_response) verifier = oauth_response.get('oauth_verifier') authorize_url = base_authorization_url + '?oauth_token=' authorize_url = authorize_url + resource_owner_key print 'Please go here and authorize,', authorize_url verifier = raw_input('Please input the verifier') I have found this kind of example from internet but it gives an error like :
AttributeError: 'OAuth1' object has no attribute 'authorization_url' I have checked the session info and actually there is authorization_url here: https://github.com/requests/requests-oauthlib/blob/master/requests_oauthlib/oauth1_session.py