0

I cannot get the List of file from the Dropbox.

 package com.example.contactmaster.dropbox_api;

    import java.util.ArrayList;
    import android.os.AsyncTask;

    import com.dropbox.client2.DropboxAPI;
    import com.dropbox.client2.DropboxAPI.Entry;
    import com.dropbox.client2.android.AndroidAuthSession;
    import com.dropbox.client2.exception.DropboxException;

    public class ListFiles extends AsyncTask<Void, Void, Boolean> {
        private DropboxAPI<AndroidAuthSession> dropboxApi;
        private String path;

        public ListFiles(DropboxAPI<AndroidAuthSession> dropbox, String fILE_DIR) {
            // TODO Auto-generated constructor stub
            dropboxApi = dropbox;
            path = fILE_DIR;
        }

        @Override
        protected Boolean doInBackground(Void... params) {
            System.out.println("=== List File ");
            ArrayList<String> files = new ArrayList<String>();
            try {
                Entry directory = dropboxApi.metadata(path, 1000, null, true, null);
                for (Entry entry : directory.contents) {
                    if (!entry.isDir)
                        files.add(entry.fileName());
                    else
                        files.add("___" + entry.fileName());
                }

                System.out.println("=== Array List : " + files.size());
            } catch (DropboxException e) {
                e.printStackTrace();
            }

            return true;
        }

    }

I created this AsyncTask and call from the MainActivity like.

The error code of the my log file is

05-21 18:52:32.702: W/genymotion_audio(122): out_write() limiting sleep time 58049 to 23219 
05-21 18:52:32.710: I/System.out(7603): === List File 
05-21 18:52:32.726: W/genymotion_audio(122): out_write() limiting sleep time 28049 to 23219
05-21 18:52:33.978: W/System.err(7603): DropboxServerException (nginx): 400 Bad Request (App folder (sandbox) access attempt failed because this app is not configured to have an app folder.  Should your access type be 'dropbox' instead?)
05-21 18:52:33.978: W/System.err(7603):     at com.dropbox.client2.RESTUtility.parseAsJSON(Unknown Source)
05-21 18:52:33.982: W/System.err(7603):     at com.dropbox.client2.RESTUtility.execute(Unknown Source)
05-21 18:52:33.990: W/System.err(7603):     at com.dropbox.client2.RESTUtility.execute(Unknown Source) 
05-21 18:52:33.994: W/System.err(7603):     at com.dropbox.client2.RESTUtility.streamRequest(Unknown Source) 
05-21 18:52:33.994: W/System.err(7603):     at com.dropbox.client2.RESTUtility.request(Unknown Source)
05-21 18:52:33.994: W/System.err(7603):     at com.dropbox.client2.DropboxAPI.metadata(Unknown Source)
05-21 18:52:33.998: W/System.err(7603):     at com.example.contactmaster.dropbox_api.ListFiles.doInBackground(ListFiles.java:26) 
05-21 18:52:33.998: W/System.err(7603):     at com.example.contactmaster.dropbox_api.ListFiles.doInBackground(ListFiles.java:1)    05-21 18:52:33.998: W/System.err(7603):  at android.os.AsyncTask$2.call(AsyncTask.java:287) 
05-21 18:52:33.998: W/System.err(7603):     at java.util.concurrent.FutureTask.run(FutureTask.java:234) 
05-21 18:52:33.998: W/System.err(7603):     at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:230) 
05-21 18:52:33.998: W/System.err(7603):     at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1080)     
05-21 18:52:33.998: W/System.err(7603):     at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:573)    
05-21 18:52:34.002: W/System.err(7603):     at java.lang.Thread.run(Thread.java:856)
Navdroid
  • 1,541
  • 3
  • 25
  • 52
Gaurav Mandlik
  • 525
  • 1
  • 9
  • 42
  • Where do you initialize your `AndroidAuthSession`? Are you by chance using this deprecated constructor and passing in the wrong access type? https://www.dropboxstatic.com/static/developers/dropbox-android-sdk-1.6.3-docs/com/dropbox/client2/android/AndroidAuthSession.html#AndroidAuthSession(com.dropbox.client2.session.AppKeyPair,%20com.dropbox.client2.session.Session.AccessType) – user94559 May 21 '15 at 15:18
  • DropboxAPI dropbox = new DropboxAPI(session); this is delare in my mainActivity class in onCreate() – Gaurav Mandlik May 22 '15 at 05:01
  • Okay, but where do you initialize the `AndroidAuthSession` itself? – user94559 May 22 '15 at 06:17
  • AndroidAuthSession initialize in my mainActivity and from that activity i call above ListFiles Async Task – Gaurav Mandlik May 22 '15 at 09:01
  • Please share the code that initializes the `AndroidAuthSession`. I believe you might be using the deprecated constructor I mentioned earlier and passing the wrong value for the access type. – user94559 May 22 '15 at 15:13
  • in My Activity Declare the varialble as DropboxAPI dropboxApi; and then initialize that variable in onCreate() like dropboxApi = new DropboxAPI(session); – Gaurav Mandlik May 23 '15 at 05:33
  • "the code that initializes the `AndroidAuthSession`" means the code that looks something like `AndroidAuthSession session = ...`. Have you checked that code to see if you're using the deprecated constructor that I mentioned? – user94559 May 23 '15 at 06:41
  • ok my mistake for understanding now is understand what u ask i declare like that AndroidAuthSession session = new AndroidAuthSession(appKeyPair, ACCESS_TYPE, token); – Gaurav Mandlik May 23 '15 at 06:50
  • So yes, you're using one of the deprecating constructors. I imagine that you're passing an ACCESS_TYPE that doesn't match the permission of your actual app. Please just switch to using one of the supported constructors (e.g. `new AndroidAuthSession(appKeyPair, token);`). – user94559 May 23 '15 at 06:53
  • oh.. ok can you give me some hint or example to easily understand me. – Gaurav Mandlik May 25 '15 at 12:19
  • I already gave you the exact code to write. I don't know how to be clearer. – user94559 May 25 '15 at 16:45
  • ok thaks for the responce. – Gaurav Mandlik May 26 '15 at 04:47

1 Answers1

0
if (key != null && secret != null) {
    AccessTokenPair token = new AccessTokenPair(key, secret);
    session = new AndroidAuthSession(appKeyPair, ACCESS_TYPE, token);
} else {
    session = new AndroidAuthSession(appKeyPair, ACCESS_TYPE);
}

dropboxApi = new DropboxAPI<AndroidAuthSession>(session);
Nic
  • 12,220
  • 20
  • 77
  • 105