cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Announcements
Share your feedback on the Document Scanning Experience in the Dropbox App right here.

Dropbox API Support & Feedback

Find help with the Dropbox API from other developers.

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Re: Examples for list folder using dropbox java api v2

Examples for list folder using dropbox java api v2

malark
Helpful | Level 5
Go to solution

Hi, I am trying to use dropbox client api v2 with java HttpURLConnection to list folders in dropbox. The below example did not work. It returns 400 Bad request. Can you please help me ?

 

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;

public class DBClientService {

    private static final String token = "Bearer XXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
   public static void main(String[] args) {
        
      try {

        URL url = new URL("https://api.dropboxapi.com/2/files/list_folder");
        HttpURLConnection conn = (HttpURLConnection) url.openConnection();
        conn.setRequestProperty("Accept", "application/json");        
        conn.addRequestProperty ("Authorization", token);
        conn.setRequestMethod("POST");
        conn.setRequestProperty("Content-Type", "application/json");
        conn.addRequestProperty("path", "/test_java_createfolder");
        conn.addRequestProperty("recursive", "false");
        conn.addRequestProperty("include_media_info", "false");
        conn.addRequestProperty("include_deleted", "false");
        conn.addRequestProperty("include_has_explicit_shared_members", "false");
        
        if (conn.getResponseCode() != 200) {
            System.out.println(conn.getResponseMessage());
            throw new RuntimeException("Failed : HTTP error code : "
                    + conn.getResponseCode());
        }

        BufferedReader br = new BufferedReader(new InputStreamReader(
            (conn.getInputStream())));

        String output;
        System.out.println("Output from Server .... \n");
        while ((output = br.readLine()) != null) {
            System.out.println(output);
        }

        conn.disconnect();

      } catch (MalformedURLException e) {

        e.printStackTrace();

      } catch (IOException e) {

        e.printStackTrace();

      }

    }

}
1 Accepted Solution

Accepted Solutions
1 Reply 1

malark
Helpful | Level 5
Go to solution
Need more support?