Get app key and secret here. Save them to a file called dropbox.txt
.
with open("dropbox.txt") as f:
app_key,app_secret = f.readlines()
app_key,app_secret = app_key.strip(),app_secret.strip()
Following this tutorial.
import dropbox
flow = dropbox.client.DropboxOAuth2FlowNoRedirect(app_key, app_secret)
authorize_url = 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.'
1. Go to: https://www.dropbox.com/1/oauth2/authorize?response_type=code&client_id=hvgd9nm3q2o6pmr 2. Click "Allow" (you might have to log in first) 3. Copy the authorization code.
code = raw_input("Enter the authorization code here: ").strip()
Enter the authorization code here: 76ZCZZZQ_pYAAAAAAAAAAX1oMc2vEawMRylNvHIKpww
access_token, user_id = flow.finish(code)
client = dropbox.client.DropboxClient(access_token)
print 'linked account: ', client.account_info()['display_name']
linked account: yoav ram
fname = "github-wolverine.jpg"
f, metadata = client.get_file_and_metadata('/' + fname)
out = open(fname, 'wb')
out.write(f.read())
out.close()
print metadata['size']
93.4 KB
from IPython.core.display import Image
Image(filename=fname)