]>
jfr.im git - z_archive/twitter.git/blob - twitter/oauth_dance.py
3 from api
import Twitter
4 from oauth
import OAuth
, write_token_file
6 def oauth_dance(app_name
, consumer_key
, consumer_secret
, token_filename
=None):
8 Perform the OAuth dance with some command-line prompts. Return the
9 oauth_token and oauth_token_secret.
11 Provide the name of your app in `app_name`, your consumer_key, and
12 consumer_secret. This function will open a web browser to let the
13 user Allow your app to access their Twitter account. PIN
14 authentication is used.
16 If a token_filename is given, the oauth tokens will be written to
19 print ("Hi there! We're gonna get you all set up to use %s." % app_name
)
21 auth
=OAuth('', '', consumer_key
, consumer_secret
),
23 oauth_token
, oauth_token_secret
= parse_oauth_tokens(
24 twitter
.oauth
.request_token())
26 In the web browser window that opens please choose to Allow
27 access. Copy the PIN number that appears on the next page and paste or
31 'http://api.twitter.com/oauth/authorize?oauth_token=' +
33 time
.sleep(2) # Sometimes the last command can print some
34 # crap. Wait a bit so it doesn't mess up the next
36 oauth_verifier
= raw_input("Please type the PIN: ").strip()
39 oauth_token
, oauth_token_secret
, CONSUMER_KEY
, CONSUMER_SECRET
),
41 oauth_token
, oauth_token_secret
= parse_oauth_tokens(
42 twitter
.oauth
.access_token(oauth_verifier
=oauth_verifier
))
45 token_filename
, oauth_token
, oauth_token_secret
)
47 print "That's it! Your authorization keys have been written to %s." % (
48 options
['oauth_filename'])
49 return oauth_token
, oauth_token_secret