You might see that the Dropbox Community team have been busy working on some major updates to the Community itself! So, here is some info on what’s changed, what’s staying the same and what you can expect from the Dropbox Community overall.

Forum Discussion

nzmike's avatar
nzmike
Explorer | Level 3
7 years ago

Android API - listfolder returns nothing

I have to admit here that I'm both new to Android and new to the DropBox API (but not new to development) so maybe I'm doing something wrong but I cannot get listFolder to return any files no matter what I try.

 

My code is below and the loop that gets the files is taken from the example API code. There is no issue conencting with the API but no matter what path I put in I either get nothing (if I use "") or an exception if use any other path.

 

One other thing I'm also confused about - once I've set up an app in the DropBox dashboard (say it's called MyTestApp) do I then need to create a folder of the same name in the root of my DropBox folder?  If not, where is the folder for the app to be found?  I am assuming using "" as the path is the same as saying DropBox/MyTestApp.  I have 5 files of mixed type in this folder but the code never returns anything.... can anyone help me out to get this working?

 

public class MainActivity extends AppCompatActivity {

private List<TestClass> filesList;

final static private String APP_KEY = "yyyyyyyyyyyy";
final static private String ACCESS_TOKEN = "xxxxxxxxxxx";

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

//I KNOW THIS IS NOT GOOD CODE BUT I JUST WANT TO GET THE listFolder WORKING
//BEFORE MAKING A SEPERATE FUNCTION FOR THIS.

StrictMode.ThreadPolicy policy = new
StrictMode.ThreadPolicy.Builder().permitAll().build();
StrictMode.setThreadPolicy(policy);

DropboxClientFactory dbFactory = new DropboxClientFactory(ACCESS_TOKEN);
DbxClientV2 client = dbFactory.getClient();

//TestClass is just a simlpe class with an integer and a string
filesList = new ArrayList<TestClass>();

try {
ListFolderResult result = client.files().listFolder("");
while (true) {
for (Metadata metadata : result.getEntries()) {
System.out.println(metadata.getPathLower()); //Never prints anything
filesList.add(new TestClass(metadata.getPathLower()));
}

if (!result.getHasMore()) {
break;
}

result = client.files().listFolderContinue(result.getCursor());
}
}
catch (DbxException ex)
{
System.out.println("EXCEPTION getting DropBox Files list: " + ex.getMessage());
}
}
}

 

  • Just registering an app (i.e., creating it on the App Console), does not automatically create the "app folder" in your account. The app folder is only created in the account once the app is "linked" to the account (i.e., when the user goes through the OAuth app authorization flow to authorize the app to connect to their account, or, for the account that owns the app, when you click the "Generate" button on the app's page on the App Console to get an access token for your app-account pair).

    You don't need to delete or recreate any app or folder, nor do you need to make an API call to determine the path. (Apps with the app folder permission don't need to know the full path of the app folder. All paths in API calls made by apps with the app folder permission are automatically used relative to the app folder.)

    I recommend going to https://www.dropbox.com/ to browse your account. Assuming your account is set to English, the app folder(s) will be inside a folder named "Apps".

    There's an example Android app here:

    https://github.com/dropbox/dropbox-sdk-java/tree/master/examples/android
  • Greg-DB's avatar
    Greg-DB
    Icon for Dropbox Staff rankDropbox Staff
    If you registered your app to use the "app folder" permission (e.g., as opposed to "full Dropbox"), the app will only be able to see files inside the special app folder created for it. Any paths you use will be automatically interpreted relative to that app folder.

    The app folder is by default (for the English locale) created in the account at /Apps/<app folder name>. You do not need to make this yourself.

    By default, this folder is empty, so it sounds you just haven't put anything in the app folder yet, and the so listFolder is accordingly returning an empty list.
    • nzmike's avatar
      nzmike
      Explorer | Level 3

      Hi Greg, many thanks for the answer. 

       

      I already had an Apps folder in my DropBox  (created by me a while back for another purpose) and when I add a new app to the dashboard the app folder is not being created within Apps - could the fact that I created the Apps folder myself be the issue?

       

      Since the dashboard didn't create the appropriate app folder I went ahead and created it myself  (e.g: Apps/MyTestApp1) and copied files to it but still nothing is picked up.

       

      Perhaps I should I delete my Apps folder, delete the app from my dashboard and start again?  

       

      Alternatively, is there an API call that I can use to find what DropBox thinks the default folder is?  (I'll look up the API docs as well of course)

       

       

      Finally, just so I'm really clear, can you confirm that if I go into my dashboard and create a new app, say MyTestApp2, then when I refresh my DropBox there should a MyTestApp2 folder inside the Apps folder?  I'm just concerned I'm missing some really fundamental step that may be obvious to experienced DropBoxAPI users but perhaps not to first-timers like me.  I was unable to find an Android app example from scratch so I'm just using scraps of knowledge from all over the place.

      • Greg-DB's avatar
        Greg-DB
        Icon for Dropbox Staff rankDropbox Staff
        Just registering an app (i.e., creating it on the App Console), does not automatically create the "app folder" in your account. The app folder is only created in the account once the app is "linked" to the account (i.e., when the user goes through the OAuth app authorization flow to authorize the app to connect to their account, or, for the account that owns the app, when you click the "Generate" button on the app's page on the App Console to get an access token for your app-account pair).

        You don't need to delete or recreate any app or folder, nor do you need to make an API call to determine the path. (Apps with the app folder permission don't need to know the full path of the app folder. All paths in API calls made by apps with the app folder permission are automatically used relative to the app folder.)

        I recommend going to https://www.dropbox.com/ to browse your account. Assuming your account is set to English, the app folder(s) will be inside a folder named "Apps".

        There's an example Android app here:

        https://github.com/dropbox/dropbox-sdk-java/tree/master/examples/android

About Dropbox API Support & Feedback

Node avatar for Dropbox API Support & Feedback

Find help with the Dropbox API from other developers.

5,912 PostsLatest Activity: 2 hours ago
333 Following

If 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!