cancel
Showing results for 
Search instead for 
Did you mean: 
Announcements
Update: Find information on Dropbox support during COVID-19 here
Close
cancel
Showing results for 
Search instead for 
Did you mean: 
Highlighted

API v2 get_current_user error

New member | Level 1
New member | Level 1

Hi.

i've bumped into this issue migrating from v1 to v2:

after getting the auth code from this endpoint:

https://www.dropbox.com/oauth2/authorize

and getting the token from this endpoint:
https://api.dropbox.com/oauth2/token

i am trying to get user's display name. as far as i understand you've changed user endpoint to this one:

https://api.dropboxapi.com/2/users/get_current_account

but all i get from api is this:

{protocol=http/1.1, code=400, message=Bad Request, url=https://api.dropboxapi.com/2/users/get_current_account}

The same code works fine with api v1. Please give me hints if you have any.

7 Replies 7
Highlighted

Re: API v2 get_current_user error

Dropboxer
Dropboxer

[Cross-linking for reference: https://stackoverflow.com/questions/39074097/dropbox-api-v2-get-current-user ]

Can you post the full response body? It should have a more useful error message.

Highlighted

Re: API v2 get_current_user error

New member | Level 1
New member | Level 1

there's nothing in response body, only this message:

Response{protocol=http/1.1, code=400, message=Bad Request, url=https://api.dropboxapi.com/2/users/get_current_account}

response headers:

0 = "Server"
1 = "nginx"
2 = "Date"
3 = "Fri, 26 Aug 2016 10:10:19 GMT"
4 = "Content-Type"
5 = "text/plain; charset=utf-8"
6 = "Content-Length"
7 = "163"
8 = "Connection"
9 = "keep-alive"
10 = "Content-Disposition"
11 = "attachment; filename=unspecified"
12 = "Content-Security-Policy"
13 = "sandbox"
14 = "Vary"
15 = "Dropbox-API-Arg, Authorization"
16 = "X-Content-Security-Policy"
17 = "sandbox"
18 = "X-Dropbox-Request-Id"
19 = "fabc4a62296d3264878e3fb2af1224eb"
20 = "X-Webkit-Csp"
21 = "sandbox"
22 = "OkHttp-Sent-Millis"
23 = "1472206218027"
24 = "OkHttp-Received-Millis"
25 = "1472206218482"

i hope it helps

Highlighted

Re: API v2 get_current_user error

Dropboxer
Dropboxer

"there's nothing in response body"

This is very unlikely to be true. I don't think the Dropbox API ever returns a 400 response without a response body explaining the issue.

Can you share the code you're using to read the response body?

Highlighted

Re: API v2 get_current_user error

Dropboxer
Dropboxer

In fact, this header indicates there's a 163-byte response. You'll need to read that response to see what the error is.

6 = "Content-Length"
7 = "163"
Highlighted

Re: API v2 get_current_user error

New member | Level 1
New member | Level 1

Here's my code:

private static final String DROPBOX_TOKEN_ENDPOINT = "https://api.dropbox.com/oauth2/token";
private static final String DROPBOX_ACCOUNT_INFO_ENDPOINT = "https://api.dropboxapi.com/2/users/get_current_account";
 OkHttpClient client = new OkHttpClient();

RequestBody body = new MultipartBuilder().type(MultipartBuilder.FORM)
.addFormDataPart("code", code)
.addFormDataPart("grant_type", "authorization_code")
.addFormDataPart("client_id", AuthKeyConstants.DROPBOX_APP_KEY)
.addFormDataPart("client_secret", AuthKeyConstants.DROPBOX_APP_SECRET)
.addFormDataPart("redirect_uri", AuthKeyConstants.DROPBOX_REDIRECT_URL)
.build();
Request request = new Request.Builder()
.url(DROPBOX_TOKEN_ENDPOINT)
.post(body)
.build();
try {
Response response = client.newCall(request).execute();
if (response.isSuccessful()) {
String responseBody = response.body().string();
JsonObject json = (JsonObject) new JsonParser().parse(responseBody);
String accessToken = json.get("access_token").getAsString();
String accountId = json.get("uid").getAsString();
response.body().close();
Request userRequest = new Request.Builder()
.url(DROPBOX_ACCOUNT_INFO_ENDPOINT)
.addHeader("Authorization", "Bearer " + accessToken)
.build();
Response accountResponse = client.newCall(userRequest).execute();
if (accountResponse.isSuccessful()) {
responseBody = accountResponse.body().string();
accountResponse.body().close();
json = (JsonObject) new JsonParser().parse(responseBody);
String userName = json.get("name").getAsJsonObject().get("display_name").getAsString();
// save new Dropbox account here
} else {
return ERROR_RESPONSE_UNSUCCESSFUL;
}
} else {
return ERROR_RESPONSE_UNSUCCESSFUL;
}
} catch (IOException e) {
e.printStackTrace();
return ERROR_EXCEPTION;
}

The first call is a success, i get access_token no problem from there. I used debugging to see everything in accountResponse and this is what i got: success = false, body = null, code=400, message=Bad Request, url=https://api.dropboxapi.com/2/users/get_current_account}

Highlighted

Re: API v2 get_current_user error

Dropboxer
Dropboxer

How about this so you can see the actual response body?

} else {
String responseBody = accountResponse.body().string();
// log or just inspect responseBody

accountResponse.body().close();

return ERROR_RESPONSE_UNSUCCESSFUL;
}
Highlighted

Re: API v2 get_current_user error

New member | Level 1
New member | Level 1

ok. now i get it. thank you.

Error in call to API function "users/get_current_account": Your request's HTTP request method is "GET".  This function only accepts the HTTP request method "POST".

changing to post

Work Smarter with Dropbox

The way we work is changing. Share and discover new ways to work smarter with Dropbox in our community.

Sound good? Let's get started.
Who's talking

Top contributors to this post

What do Dropbox user levels mean?
Need more support?