Using OAuth2 to Get file list On Dropbox

If API is already deprecated, please report it by using this button

Goal

We wanted to figure out the easiest way to use OAuth to get file list from Dropbox on behalf of a Dropbox user using Javascript. Here is how we did it with OAuth.io.

Code Snippet

Try this snippet. Once you log in with your Dropbox account it will get the list of files in your account. Feel free to tweak it to get file list from different folders, etc.

https://jsfiddle.net/p187m5ur/6/

Code Explanation:

HTML

<a id="dropbox-button" class="btn btn-block btn-social btn-dropbox">
  <i class="fa"></i> Get file list
</a>

CSS

None

JavaScript

var params = {
  "path": ""
};
$('#dropbox-button').on('click', function() {
  // Initialize with your OAuth.io app public key
  OAuth.initialize('OAUTH_IO_PUBLIC_KEY');
  // Use popup for oauth
  // Alternative is redirect
  OAuth.popup('dropbox').then(provider => {
    console.log('provider:', provider);
    alert("You can check Dropbox provider object in browser console.");

    provider.post({
      url: "/files/list_folder",
      data: JSON.stringify(params),
      headers: {
         "Content-Type": "application/json"
      }
    }).then(data =>             {
      console.log('Files:', data);
      alert("You can find file list in browser console");
    });
  });
})

External Requirements

This Javascript code has external requirements:

Step-by-step Guide

Here is a summary of the steps to create this social button to get file list from Dropbox on a user's behalf using OAuth2.

  1. Create a Dropbox account, if you do not have one
  2. Create an app on Dropbox using this simple step-by-step guide
  3. Copy your Dropbox app client id and client secret
  4. Signup for OAuth.io account
  5. filesfilesfilesfiles your Dropbox app with OAuth.io by pasting your Dropbox app client id and client secret into OAuth.io
  6. Copy the OAuth javascript snippet (https://jsfiddle.net/p187m5ur/6/) on to your web page

Live example code for using OAuth to Get file list via Dropbox