def main(): configFile = argv[1] config = SafeConfigParser() config.read(configFile) consumer_key = config.get('consumer', 'key') consumer_secret = config.get('consumer', 'secret') tumblr = Tumblpy(consumer_key, consumer_secret) auth_props = tumblr.get_authentication_tokens() print("Go to the following link in your browser:") print(auth_props['auth_url']) print('') oauth_verifier = 'n' while oauth_verifier.lower() == 'n': oauth_verifier = raw_input('What is the PIN?: ') tumblr = Tumblpy(consumer_key, consumer_secret, auth_props['oauth_token'], auth_props['oauth_token_secret']) authorized_tokens = tumblr.get_access_token(oauth_verifier) config.set('oauth', 'key', authorized_tokens['oauth_token']) config.set('oauth', 'secret', authorized_tokens['oauth_token_secret']) print('Saving keys to config file %s' % configFile) with open(configFile, 'w') as fp: config.write(fp)
def authorize(): # Authorization Step 1 t = Tumblpy(app_key = app_key, app_secret = app_secret) auth_props = t.get_authentication_tokens() auth_url = auth_props['auth_url'] # temp tokens oauth_token = auth_props['oauth_token'] oauth_token_secret = auth_props['oauth_token_secret'] # Authorization Step 2 t = Tumblpy(app_key = app_key, app_secret = app_secret, oauth_token=oauth_token, oauth_token_secret=oauth_token_secret, callback_url='oob') # oauth_verifier = *Grab oauth verifier from URL* # At this point, follow instructions in commandline. print "Go to the link ", auth_url print "Click 'Allow' and when the page redirects, "\ "grab the value of oauth_verifier from the URL and enter it here." oauth_verifier = raw_input('oauth_verifier:') authorized_tokens = t.get_access_token(oauth_verifier) # Final access tokens oauth_token = authorized_tokens['oauth_token'] oauth_token_secret = authorized_tokens['oauth_token_secret'] return oauth_token, oauth_token_secret