from dropbox import Dropbox
from dropbox import DropboxOAuth2FlowNoRedirect
auth_flow = DropboxOAuth2FlowNoRedirect(APP_KEY, APP_SECRET)
authorize_url = auth_flow.start()
print "1. Go to: " + authorize_url
print "2. Click \"Allow\" (you might have to log in first)."
print "3. Copy the authorization code."
auth_code = raw_input("Enter the authorization code here: ").strip()
try:
access_token, user_id = auth_flow.finish(auth_code)
except Exception, e:
print('Error: %s' % (e,))
return
dbx = Dropbox(access_token)
I got this code from http://dropbox-sdk-python.readthedocs.io/en/master/moduledoc.html#module-dropbox.oauth
Basically what I want to is, test some simple commands. In the beginning of my code I define
APP_KEY = 'mykey'
APP_SECRET = 'mysecret'
Whenever I run the code, give access to my app and put in the authorization code it gives out an error.
NameError: name 'access_token' is not defined
I am using python2.7. There is something wrong with the try/exception part, but I can not figure out what.
Can anyone help?