Advertisement
Guest User

Untitled

a guest
Jul 30th, 2014
1,411
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2. import oauth2
  3. import urlparse
  4.  
  5.  
  6. REQUEST_TOKEN_URL = 'http://www.tumblr.com/oauth/request_token'
  7. AUTHORIZATION_URL = 'http://www.tumblr.com/oauth/authorize'
  8. ACCESS_TOKEN_URL = 'http://www.tumblr.com/oauth/access_token'
  9. CONSUMER_KEY = ''
  10. CONSUMER_SECRET = ''
  11.  
  12. consumer = oauth2.Consumer(CONSUMER_KEY, CONSUMER_SECRET)
  13. client = oauth2.Client(consumer)
  14.  
  15. resp, content = client.request(REQUEST_TOKEN_URL, "GET")
  16.  
  17. request_token = dict(urlparse.parse_qsl(content))
  18. oauthToken = request_token['oauth_token']
  19. oauthSecret = request_token['oauth_token_secret']
  20.  
  21. print "Go to the following link in your browser:"
  22. print "%s?oauth_token=%s" % (AUTHORIZATION_URL, oauthToken)
  23. print
  24.  
  25. accepted = 'n'
  26. while accepted.lower() == 'n':
  27.         accepted = raw_input('Have you authorized me? (y/n) ')
  28.         oauth_verifier = raw_input('What is the PIN? ').strip()
  29.  
  30. token = oauth2.Token(request_token['oauth_token'],
  31.         request_token['oauth_token_secret'])
  32.  
  33. token.set_verifier(oauth_verifier)
  34. client = oauth2.Client(consumer, token)
  35.  
  36. resp, content = client.request(ACCESS_TOKEN_URL, "POST")
  37. access_token = dict(urlparse.parse_qsl(content))
  38.  
  39. print "Access Token:"
  40. print "    - oauth_token        = %s" % access_token['oauth_token']
  41. print "    - oauth_token_secret = %s" % access_token['oauth_token_secret']
  42. print
  43. print "You may now access protected resources using the access tokens above."
  44. print
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement