X-Git-Url: https://jfr.im/git/z_archive/twitter.git/blobdiff_plain/79d6cca767a245eb3a115f3698a9b388b36ab987..3e782f630283e9a9c1c9c5f809137b8ebe482823:/twitter/oauth_dance.py diff --git a/twitter/oauth_dance.py b/twitter/oauth_dance.py index dace720..17dbae6 100644 --- a/twitter/oauth_dance.py +++ b/twitter/oauth_dance.py @@ -1,10 +1,19 @@ +from __future__ import print_function + import webbrowser import time from .api import Twitter from .oauth import OAuth, write_token_file +try: + _input = raw_input +except NameError: + _input = input + + + def oauth_dance(app_name, consumer_key, consumer_secret, token_filename=None): """ Perform the OAuth dance with some command-line prompts. Return the @@ -12,16 +21,16 @@ def oauth_dance(app_name, consumer_key, consumer_secret, token_filename=None): Provide the name of your app in `app_name`, your consumer_key, and consumer_secret. This function will open a web browser to let the - user Allow your app to access their Twitter account. PIN + user allow your app to access their Twitter account. PIN authentication is used. If a token_filename is given, the oauth tokens will be written to the file. """ - print(("Hi there! We're gonna get you all set up to use %s." % app_name)) + print("Hi there! We're gonna get you all set up to use %s." % app_name) twitter = Twitter( auth=OAuth('', '', consumer_key, consumer_secret), - format='') + format='', api_version=None) oauth_token, oauth_token_secret = parse_oauth_tokens( twitter.oauth.request_token()) print(""" @@ -46,11 +55,11 @@ Uh, I couldn't open a browser on your computer. Please go here to get your PIN: """ + oauth_url) - oauth_verifier = input("Please enter the PIN: ").strip() + oauth_verifier = _input("Please enter the PIN: ").strip() twitter = Twitter( auth=OAuth( oauth_token, oauth_token_secret, consumer_key, consumer_secret), - format='') + format='', api_version=None) oauth_token, oauth_token_secret = parse_oauth_tokens( twitter.oauth.access_token(oauth_verifier=oauth_verifier)) if token_filename: