Dropbox exordium

Hi Readers,

The idea about this blog is to cover the basic steps which we have to do, to integrate Dropbox with our application. The readers should have a minimal understanding of access_token, webhooks.

Recently I have started to do integration for my web application. The one which I integrated first was Dropbox

The Requirements are:

Fetch the dropbox files.

Get the corresponding redirect link.

Get the shared users for a file.

To integrate Dropbox into our Application:

  1. Create a Dropbox box app in the Dropbox developers site.
  2. After creation, use the ClientId and Client Secret of the app for authentication.

How to authenticate a user ??

The auth process can be done in two ways:

1. By creating a separate login.

2. By Click on a particular redirect link.

Note: The API URL should be encoded with client ID obtained.

Example:

https://www.dropbox.com/oauth2/authorize?response_type=code&client_id=” ”redirect_uri=””’

Redirect URI  →  The endpoint to receive the auth credentials.

After successful authentication, the auth credentials can be obtained in the redirect_uri.

Ohh, Wait! We are not close to getting the files.

Use the auth code, to get the Access_token for a user. Hit the following API endpoint with the auth code. https://api.dropboxapi.com/oauth2/token

Sample code:

let options = {

               url:https://api.dropboxapi.com/oauth2/token,

               qs: {
                  
                   'code': authCode,(code obtained by authentication)

                   'grant_type': 'authorization_code',

                   'client_id': '',

                   'client_secret': '',

                   'redirect_uri': ''

               },

               method: 'POST',

               json: true

           }

           return request_promise(options);

I have used request_promise to get the results. The redirect_uri should be same as the redirect URI provided during authentication.

Things to remember:

1. Redirect URI should be the same.

2. The Dropbox Client Id and Client Secret should be entered.

Hooray! We completed the process
Heaven, the dropbox access token will never expire.

The access token can be removed by only revoking.

How to drag the files from Dropbox to our App ??

The files  can be obtained by hitting the  following API endpoint :

https://api.dropboxapi.com/2/files/list_folder

The API returns the folders and files in a one-way tree. Nested files and folders can be obtained by setting the recursive field to true in the API hit.

Webhooks hit:

The Webhook hit can be configured in the Dropbox app which we created. Specify the corresponding webhooks URL. For authentication, the App will verify the URL by hitting with a challenge parameter. The app should be responded back with the challenge parameter.

Once the authentication is done, the webhooks hits the URL whenever the user of our app drops some files in their Dropbox.

References:

The dropbox also provides an API Explorer where the developers can view the live functioning of the API Endpoints

https://dropbox.github.io/dropbox-api-v2-explorer/

To know more about Dropbox  integration visit this link: https://www.dropbox.com/developers