Accessing Dropbox files via RESTful API

In this article, I will guide you through the steps to access Dropbox files from an app. If you want to skip the document and see some sample code; check my following pet projects accessing Dropbox:

App Registration

Assuming that you have a working Dropbox account, you should go to https://www.dropbox.com/developers/apps and create a new app. The steps are very straightforward and intuitive.

Here are the recommended settings for a simple access model:

  • Status: Development
  • Development users: Only you
  • Permission type: App folder
  • App folder name: my_app_folder (or whatever you want)
  • OAuth2
    • Redirect URI’s: (empty)
    • Allow implicit grant: Allow
  • Chooser / saver / embedder domains: (empty)
  • Webhooks: (empty)

Note your app key & app secret. You will need those later.

Development

Authorization (get code)

Forward your user to the URL: https://www.dropbox.com/oauth2/authorize?client_id=YOUR_DROPBOX_APP_KEY&response_type=code

When the user authenticates here, he/she will copy a code to the clipboard and come back to your app. This code symbolizes that he/she is allowing your app to access his/her Dropbox folder.

Ask the user for that code via your GUI.

Authentication (get token)

In the background, go to the URL https://api.dropboxapi.com/oauth2/token?code=USER_CODE&grant_type=authorization_code via HTTP POST. The header should contain:

  • Authorization: Basic APP_KEY:APP_SECRET

Dropbox will hopefully return a token to you. From now on, you will include this token to your future requests whenever you want to access the users Dropbox folder.

At this point, my_app_folder (or whatever name you gave) will be created in the Dropbox folder of the client.

Download file

Go to https://content.dropboxapi.com/2/files/download over HTTP POST. The header should contain:

  • Authorization: Bearer USERTOKEN
  • Dropbox-API-Arg: {“path”: “/YOUR_FILE_TO_DOWNLOAD.TXT”}

Dropbox will hopefully return the requested file to you. Please note that the file must be placed in the app folder that DropBox created for you (my_app_folder or whatever).

Conclusion

This document demonstrated the most basic way to add Dropbox functionality to your app. Please note that Dropbox provides many further options; such as:

  • Accessing the entire Dropbox structure of the user
  • Redirecting (in case you are writing a Web app)
  • Web hooks
  • etc…

I’m leaving the further discovery to you.

Advertisement

by

Tags:

Comments

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s