cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Announcements
Want to learn some quick and useful tips to make your day easier? Check out how Calvin uses Replay to get feedback from other teams at Dropbox 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: 

Android API - listfolder returns nothing

Android API - listfolder returns nothing

nzmike
Explorer | Level 3
Go to solution

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());
}
}
}

 

1 Accepted Solution

Accepted Solutions

Greg-DB
Dropbox Staff
Go to solution
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

View solution in original post

4 Replies 4

Greg-DB
Dropbox Staff
Go to solution
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
Explorer | Level 3
Go to solution

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
Dropbox Staff
Go to solution
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

nzmike
Explorer | Level 3
Go to solution

Hi Greg, sorry it's taken a while to reply, have been away for a few days.

 

I think the issue was something to do with me having already created the Apps folder well before I started my Android app - rather than using Windows Explorer (which was showing the files in the Apps/<appname> folder when I went to Dropbox.com I could see they had not been synched.  When I tried to do that I got a synching error in Explorer and it showed two Apps folders, one with an error next to it.  I deleted the one I created manually and moved some test files to the <appname> folder and re-ran my app and now it does return the files in the Apps/<appname> folder.

 

Many thanks for your help 🙂

Need more support?
Who's talking

Top contributors to this post

  • User avatar
    nzmike Explorer | Level 3
  • User avatar
    Greg-DB Dropbox Staff
What do Dropbox user levels mean?