We're making changes to the Community, so you may have received some notifications - thanks for your patience and welcome back. Learn more here.
Forum Discussion
malark
8 years agoHelpful | Level 5
Examples for list folder using dropbox java api v2
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(); } } }
- malarkHelpful | Level 5
I am able to get the examples from net.
Link : https://www.ibm.com/developerworks/community/blogs/2f9ef931-1ac3-4d9b-a8ca-6e3f01b13889/entry/Dropbox_ReST_API_v2_to_create_folder_list_folder_get_put_and_delete_file_using_Java?lang=en
About Dropbox API Support & Feedback
Find help with the Dropbox API from other developers.
5,875 PostsLatest Activity: 58 minutes agoIf you need more help you can view your support options (expected response time for an email or ticket is 24 hours), or contact us on X or Facebook.
For more info on available support options for your Dropbox plan, see this article.
If you found the answer to your question in this Community thread, please 'like' the post to say thanks and to let us know it was useful!