DROPBOX API
Use Python to get more from Dropbox
Mihalis Tsoukalos explains how to use the Dropbox REST API with Python to create your own custom tools.
OUR EXPERT
Mihalis Tsoukalos is a systems engineer and technical writer. He’s the author of Go Systems Programming and Mastering Go, third edition.
QUICK TIP
Get the for this tutorial from the Linux Format archive: www. linuxformat. com/archives ?issue=286
This month’s tutorial will look at the Dropbox Public REST API. The programming language of choice for this tutorial is Python, but we’re also going to use curl to interact with the Dropbox API. To be able to run the Python code and the curl commands on your own, you’ll need to have a Dropbox account. So, without further ado, lets get started!
Dropbox everything!
Before coding we need an introduction to Dropbox for Developers. Your journey for developing applications that use Dropbox begins at https://developers.dropbox. com. From there, press the Documentation link at the top of the page. The screenshot (right) shows part of the main documentation page of the Dropbox REST API – feel free to browse the documentation to learn more details about it.
Among other things, in this screenshot we can see the officially supported programming languages, which at the time of writing are Swift, Objective-C, Python, .NET, Java, JavaScript and HTTP. The last one means that Dropbox offers a REST API that you can use from any programming language, provided that you’ve read about the supported endpoints (https://bit.ly/lxf286dropboxdoc) and the information that you should send and expect to receive from them. However, because it’s much more difficult to work with HTTP endpoints, this tutorial is going to use Python and the well-supported dropbox Python package. Using a package obscures most of the complexity and makes the development faster and error free.
Now that we know where to look for information about the Dropbox REST API, let’s explain how to register an application to use Dropbox.
The main screen of the LinuxFormat Dropbox program created for this tutorial. For this particular case, the access token has no expiration date but your requirements might differ.
Part of the documentation page of the Dropbox Developers web site. This is the place to look for insights on the officially supported programming languages as well as the details of the Dropbox API.
Registering an application
When developing applications that communicate with Dropbox, your first step is to register these applications. This occurs because each application has specific permissions and other security constraints. The main web page for the Dropbox App console is www.dropbox. com/developers/apps, which you should visit. That screen displays all of the existing applications that are connected to your Dropbox account.
After going there, click the Create app button to create a new application. For this tutorial we’ll call the Dropbox application LinuxFormat. Next, choose “Full Dropbox – Access to all files and folders in a user’s Dropbox” on the “Choose the type of access you need” part. This means that you can look at all files and folders on your Dropbox account. Call your application LinuxFormat. Then click the Create app button again.