I changed the storage location of the photos taken with one eye to DropBox, so I wanted to programmatically upload files at once, or get a list of files and check if all the files were uploaded, so I tried using the DropBox API I did.
I tried to move the attached sample code, but I feel that I can do various things I was trying to do by just playing with this sample code.
For the time being, this time I will install the DropBox API and make a note of how to run the sample code.
OS:Mac OS X 10.9.5 Python:Ver.2.7.7 DropBox Core API:Version 2.2.0
You need to get ** App key ** and ** App secret ** to use the DropBox API.
Sample (value registered this time)
What type of app do you want to create?:Dropbox API app
What type of data does your app need to store on Dropbox?:Files and datastores
Can your app be limited to its own folder?:YES
What type of files does your app need access to?:All file types
Provide an app name, and you're on your way .: ** App name **
You can get ** App key ** and ** App secret **.
Create a virtual environment for DropBox using virtualenv that I tried in Try using virtualenv that can build a virtual environment of Python.
$ mkdir DropBoxAPI_Test
$ virtualenv --no-site-packages DropBoxAPI_Test
$ cd DropBoxAPI_Test
$ source bin/activate
$ pip install dropbox
The environment where you can use the DropBox API is complete.
(PythonTest)% python cli_client.py
[loaded OAuth 2 access token]
Dropbox>
The sample can behave like a real terminal.
First, log in and get an Auth Key.
Dropbox>login
1. Go to: https://www.dropbox.com/1/oauth2/authorize?response_type=code&client_id=XXXXXXXXXXXXXXXXX
2. Click "Allow" (you might have to log in first).
3. Copy the authorization code.
Enter the authorization code here:
Access the URL written in 1. from a browser and press "Allow" to display the code. Enter the displayed code and press enter to complete the authentication.
Enter the authorization code here:XXXXXXXXXXXXXXXX
If the authentication is successful, there will be no log and the terminal will be in the state.
Dropbox>
Dropbox>ls
Dropbox>cd directory name
Dropbox>rm file name
There are many other things such as mkdir and mv, and you can easily operate files with this sample alone.
Recommended Posts