androiddropboxdropbox-php

Can't get the list of files from Dropbox in android


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)

Solution

  • 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);