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: 

API v2 get_current_user error

API v2 get_current_user error

Eugene G.4
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

Greg-DB
Dropbox Staff

[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.

Eugene G.4
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

Steve M.
Dropbox Staff

"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?

Steve M.
Dropbox Staff

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"

Eugene G.4
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}

Steve M.
Dropbox Staff

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

Eugene G.4
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

Need more support?
Who's talking

Top contributors to this post

  • User avatar
    Eugene G.4 New member | Level 1
  • User avatar
    Steve M. Dropbox Staff
What do Dropbox user levels mean?