Try using the DropBox Core API in Python

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.

environment

OS:Mac OS X 10.9.5 Python:Ver.2.7.7 DropBox Core API:Version 2.2.0

Preparations for running the sample app

You need to get ** App key ** and ** App secret ** to use the DropBox API.

  1. Log in to DropBox from your web browser
  2. Open the "..." button at the bottom of the screen and press "For developers"
  3. Press "App Console" on the left menu
  4. Click "Create App" and enter the required information.
  1. Click "Create App" at the bottom to register

You can get ** App key ** and ** App secret **.

Install DropBox API

Create a virtual environment for DropBox using virtualenv that I tried in Try using virtualenv that can build a virtual environment of Python.

  1. Create a project directory
$ mkdir DropBoxAPI_Test
  1. Execute the virtualenv command
$ virtualenv --no-site-packages DropBoxAPI_Test
  1. Start virtual environment
$ cd DropBoxAPI_Test
$ source bin/activate
  1. Install DropBox API
$ pip install dropbox

The environment where you can use the DropBox API is complete.

Run sample app

  1. Select Python in Install Core API SDKs and download the SDK for Python from *** Download Python SDK ***. To do. (Current version: dropbox-python-sdk-2.2.0.zip)
  2. Extract the downloaded dropbox-python-sdk-X.X.X.zip
  3. Copy ** cli_client.py ** to the DropBox API_Test you just created
  4. Run cli_client.py
(PythonTest)% python cli_client.py
  1. Complete if the following terminal-like output is output
[loaded OAuth 2 access token]
Dropbox>

Other

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>

Get list

Dropbox>ls

Directory move

Dropbox>cd directory name

Delete

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

Try using the DropBox Core API in Python
Try using the Wunderlist API in Python
Try using the Kraken API in Python
Try using the BitFlyer Ligntning API in Python
Tweet using the Twitter API in Python
Try hitting the YouTube API in Python
Try using ChatWork API and Qiita API in Python
Try using the Twitter API
Try using the Twitter API
Try using the PeeringDB 2.0 API
Initial settings when using the foursquare API in python
Using the National Diet Library Search API in Python
Getting the arXiv API in Python
Hit the Sesami API in Python
Try using Pleasant's API (python / FastAPI)
Try using LevelDB in Python (plyvel)
Hit the web API in Python
Try using Python argparse's action API
Try using the Python Cmd module
Access the Twitter API in Python
Try using Leap Motion in Python
Try using the HL band in order
Try using Dropbox API v2 with Go
Get Youtube data in Python using Youtube Data API
Quickly try Microsoft's Face API in Python
Try hitting the Spotify API in Django.
Regularly upload files to Google Drive using the Google Drive API in Python
Try using FireBase Cloud Firestore in Python for the time being
[Cloudian # 7] Try deleting the bucket in Python (boto3)
Run Google Analytics API (core v3) in python
Python: Try using the UI on Pythonista 3 on iPad
Get image URL using Flickr API in Python
Evernote API in Python
Try using the Python web framework Tornado Part 1
Tips for hitting the ATND API in Python
Let's judge emotions using Emotion API in Python
Pre-process the index in Python using Solr's ScriptUpdateProcessor
Try using the collections module (ChainMap) of python3
C API in Python 3
Try using the Python web framework Tornado Part 2
Try implementing the Monte Carlo method in Python
Hit the Firebase Dynamic Links API in Python
Try using Tweepy [Python2.7]
Try accessing the YQL API directly from Python 3
To automatically send an email with an attachment using the Gmail API in Python
Continue to retrieve tweets containing specific keywords using the Streaming API in Python
Upload JPG file using Google Drive API in Python
[Unity (C #), Python] Try running Python code in Unity using IronPython
[AWS IoT] Register things in AWS IoT using the AWS IoT Python SDK
Determine the threshold using the P tile method in python
Get LEAD data using Marketo's REST API in Python
Send and receive Gmail via the Gmail API using Python
Try to delete tweets in bulk using Twitter API
OpenVINO using Inference Engine Python API in PC environment
Using the LibreOffice app in Python (1) Where are the macros?
A little bit from Python using the Jenkins API
Hit Mastodon's API in Python
[Python] Try using Tkinter's canvas
Download the file in Python
Find the difference in Python
Try using Kubernetes Client -Python-