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 :
- Creating a new Dropbox Platform app.
- Fetching and parsing Dropbox metadata information.
- Posting of Dropbox metadata information on Klipfolio Dashboard using Klipfolio API.
Brief description of these steps are as follows :
- Create a new Dropbox Platform app :
- What type of app do you want to create?
- What type of data does your app need to store on Dropbox?
- Can your app be limited to its own folder?
- What type of files does your app need access to?
- Provide an app name, and you're on your way.
- Term of Service.
- Fetching and parsing Dropbox metadata information
- Create a new java project in eclipse.
- Download and import the Dropbox Java SDK packages, available here-> https://www.dropbox.com/developers/core/sdks/java
- Add external Jar that you have download.
- And build your program according to given directions below.
Goto this url : https://www.dropbox.com/developers/apps/create. You will be asked set of questions, follow step given below:
Pages will look like:
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.
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",
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.
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: