Created
January 31, 2016 13:55
-
-
Save vik-y/adc2ef649e5fb455dc46 to your computer and use it in GitHub Desktop.
A simple python script to upload files to dropbox
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
''' | |
Instructions | |
First go to : https://www.dropbox.com/developers-v1/apps/create | |
Then create a "Drop ins app" there. | |
Now go to that from your dropbox apps console to get app_key and app_secret. | |
''' | |
import dropbox | |
app_key = 'APP_KEY_HERE' | |
app_secret = 'APP_SECRET_HERE' | |
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.' | |
code = raw_input("Enter the authorization code here: ").strip() | |
# This will fail if the user enters an invalid authorization code | |
access_token, user_id = flow.finish(code) | |
client = dropbox.client.DropboxClient(access_token) | |
print 'linked account: ', client.account_info() | |
print "---------One Time Process Done---------" | |
print "\n" | |
print "Your access token is:", access_token | |
# You need to save this access_token obtained in some text file. | |
# and then refer to upload.py |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
''' | |
A very simple program to demonstrate how to upload a file on dropbox | |
Usage: python upload.py filename | |
''' | |
import dropbox | |
import sys | |
access_token = 'ACCESS_TOKEN_OBTAINED' # Put the access token obtained from previous file here | |
client = dropbox.client.DropboxClient(access_token) | |
print 'linked account: ', client.account_info() | |
f = open(sys.argv[1], 'rb') | |
response = client.put_file('/test/'+sys.argv[1], f) | |
print "uploaded:", response | |
# Feel free to change it as per your requirements. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
dropbox api v1 doesn't work anymore.