Dropbox-Klipfolio Integration Using Java

Recently we did an Integration of Dropbox and Klipfolio using Java. The goal of this integration is to show the metadata information of files and folders from Dropbox account to the Klipfolio-Dashboard with the help of Dropbox Core API. Klipfolio is an online dashboard platform for building real-time business dashboards that contains KPI, Reports using Charts etc.
Klipfolio also provide the standard connector for connecting with Dropbox, but it does not support the fetching of metadata information so we did it programmatically using Java. The Integration is divided into three steps :

  1. Creating a new Dropbox Platform app.
  2. Fetching and parsing Dropbox metadata information.
  3. Posting of Dropbox metadata information on Klipfolio Dashboard using Klipfolio API.

Brief description of these steps are as follows :

  1. Create a new Dropbox Platform app :
  2. Goto this url : https://www.dropbox.com/developers/apps/create. You will be asked set of questions, follow step given below:

    1. What type of app do you want to create?
    2. Dropbox-Klipfolio Integration Image1

    3. What type of data does your app need to store on Dropbox?
    4. Dropbox-Klipfolio Integration Image2

    5. Can your app be limited to its own folder?
    6. Dropbox-Klipfolio Integration Image3

    7. What type of files does your app need access to?
    8. Dropbox-Klipfolio Integration Image4

    9. Provide an app name, and you're on your way.
    10. Dropbox-Klipfolio Integration Image5

    11. Term of Service.

    Dropbox-Klipfolio Integration Image6
    Pages will look like:
    Dropbox-Klipfolio Integration Image7
    Click “Create app” button and you will be redirected to new page, on next page you will find “App key” and “App secret”. Note it down it will be used in next step.
    Dropbox-Klipfolio Integration Image8

     

  3. Fetching and parsing Dropbox metadata information
  4. Create a new java project in eclipse.
  5. Download and import the Dropbox Java SDK packages, available here-> https://www.dropbox.com/developers/core/sdks/java
  6. Add external Jar that you have download.
  7. And build your program according to given directions below.

Create a new java class-“Main” and declare two final variable inside main body
final String APP_KEY = "Your APP Key";
final String APP_SECRET = "Your APP token";

Create DbxAppInfo and DbxRequestConfig objects and pass them to object of DbxWebAuthNoRedirect.

DbxAppInfo appInfo = new DbxAppInfo(APP_KEY, APP_SECRET);
DbxRequestConfig config = new DbxRequestConfig("JavaTutorial/1.0",
Locale.getDefault().toString());
DbxWebAuthNoRedirect webAuth = new DbxWebAuthNoRedirect(config, appInfo);
String authorizeUrl = webAuth.start();
System.out.println(" Go to this url and allow access: " + authorizeUrl);
System.out.println("Paste authorization code here :");

Desktop class exist in java.awt.Desktop package it will open authorize URL in default browser. Allow access in browser and paste token to console access token shown on browser window.
Dropbox-Klipfolio Integration Image9
Desktop.getDesktop().browse(java.net.URI.create(authorizeUrl));
String code = new BufferedReader(new InputStreamReader(System.in)).readLine().trim();
System.out.println("Fetching metadata from Dropbox...");

This will fail if invalid code. And client.getAccountInfo() may be used to display client information

DbxAuthFinish authFinish = webAuth.finish(code);
DbxClient client = new DbxClient(config, authFinish.accessToken);
System.out.println("Linked account: " + client.getAccountInfo().displayName);
DbxEntry.WithChildren listing = client.getMetadataWithChildren("/folder name you want to access");

Now variable “listing” will contain information of all files and folders. You may parse it to JSON or XML if you want. And post it to Klipfolio dashboard.
Output will be something like:
Dropbox-Klipfolio Integration Image10