Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import oauth2
- import urlparse
- REQUEST_TOKEN_URL = 'http://www.tumblr.com/oauth/request_token'
- AUTHORIZATION_URL = 'http://www.tumblr.com/oauth/authorize'
- ACCESS_TOKEN_URL = 'http://www.tumblr.com/oauth/access_token'
- CONSUMER_KEY = ''
- CONSUMER_SECRET = ''
- consumer = oauth2.Consumer(CONSUMER_KEY, CONSUMER_SECRET)
- client = oauth2.Client(consumer)
- resp, content = client.request(REQUEST_TOKEN_URL, "GET")
- request_token = dict(urlparse.parse_qsl(content))
- oauthToken = request_token['oauth_token']
- oauthSecret = request_token['oauth_token_secret']
- print "Go to the following link in your browser:"
- print "%s?oauth_token=%s" % (AUTHORIZATION_URL, oauthToken)
- print
- accepted = 'n'
- while accepted.lower() == 'n':
- accepted = raw_input('Have you authorized me? (y/n) ')
- oauth_verifier = raw_input('What is the PIN? ').strip()
- token = oauth2.Token(request_token['oauth_token'],
- request_token['oauth_token_secret'])
- token.set_verifier(oauth_verifier)
- client = oauth2.Client(consumer, token)
- resp, content = client.request(ACCESS_TOKEN_URL, "POST")
- access_token = dict(urlparse.parse_qsl(content))
- print "Access Token:"
- print " - oauth_token = %s" % access_token['oauth_token']
- print " - oauth_token_secret = %s" % access_token['oauth_token_secret']
- print
- print "You may now access protected resources using the access tokens above."
- print
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement