Need to see if your shared folder is taking up space on your dropbox 👨‍💻? Find out how to check here.

Forum Discussion

overjeer's avatar
overjeer
Helpful | Level 6
9 years ago
Solved

API always returns invalid_access_token, 500 error when i go to "my apps"

Hi,

 

I understand that there was some service disruption about 10 hours ago. However, I believe this has been resolved now.

 

When I generate an access token using the dropbox java sdk on my Android app, it is generating an access token fine. However, when I use this access token to authorise my account and run something like dbxClientV2.getUsers().getCurrentAccount(), it always returns an error:

 

{"error_summary": "invalid_access_token/..", "error": {".tag": "invalid_access_token"}}

 

I have tried to generate several tokens and they all return the same error.

 

Also, when I logon as a developer and go to "My Apps" it is returning me a 500 error. Does this mean that there are some API issues?

 

Any help would be appreciated. 

  • Greg-DB's avatar
    Greg-DB
    9 years ago

    You mentioned this is for an Android app, but the DbxWebAuth you're using isn't meant for Android. The API v2 Java SDK does have specific support for Android though. There's an example Android app using it here.

     

    - To set that up, your AndroidManifest.xml should be set up as shown here.

    - You start the flow by calling startOAuth2Authentication as shown here.

    - You complete the flow by calling getOAuth2Token as shown here.

    - Your app can store and re-use the resulting access token for that user, as the example does here.

    - Once you have an access token, you can make a client as shown here.

     

    For the code you are currently using though, it looks like you're getting that 'invalid_access_token' error because you're supplying an authorization code, instead of an access token.

     

    When using DbxWebAuth, you get back an "authorization code", which is not an access token. You need to exchange that authorization code for an access token, as shown here.

  • thanks mate. I will give this a go and come back to you. Thanks so much for coming back so swiftly!

6 Replies

  • Greg-DB's avatar
    Greg-DB
    Icon for Dropbox Community Moderator rankDropbox Community Moderator
    9 years ago
    Thanks for the report! The 500 on the web site definitely sounds like a bug on our side. We're looking into it.

    For the `invalid_access_token` issue, can you share the code you're using to generate and use the access token? Thanks in advance!
  • overjeer's avatar
    overjeer
    Helpful | Level 6
    9 years ago

    Thanks for your response. Here is the code:

     

    It is for my android app. I have to add that until friday it was working OK.

     

    - First I redirect the user to authorise my app. This is done by redirecting them to a URL that gets generated by this code:

     

    val request = DbxWebAuth.newRequestBuilder()
                    .withDisableSignup(true)
                    .withNoRedirect()
                    .build()
            return mWebAuth.authorize(request)

    where mWebAuth is 

     

    mWebAuth = DbxWebAuth(mConfig, mAppInfo)

    the user is redirected to a webview and if she authorises my app, a token gets generated. This token is stored and a simple command is run for verifying whether the token is valid. For this I need an instance of the DbxClientV2 so I create one:

     

    DbxClientV2(mConfig, "token code")

    Then I run the command to see whether the token generated is valid or not:

     

    client.users()?.currentAccount

    This is where I get an exception:

     

     {"error_summary": "invalid_access_token/.", "error": {".tag": "invalid_access_token"}}
  • Greg-DB's avatar
    Greg-DB
    Icon for Dropbox Community Moderator rankDropbox Community Moderator
    9 years ago

    You mentioned this is for an Android app, but the DbxWebAuth you're using isn't meant for Android. The API v2 Java SDK does have specific support for Android though. There's an example Android app using it here.

     

    - To set that up, your AndroidManifest.xml should be set up as shown here.

    - You start the flow by calling startOAuth2Authentication as shown here.

    - You complete the flow by calling getOAuth2Token as shown here.

    - Your app can store and re-use the resulting access token for that user, as the example does here.

    - Once you have an access token, you can make a client as shown here.

     

    For the code you are currently using though, it looks like you're getting that 'invalid_access_token' error because you're supplying an authorization code, instead of an access token.

     

    When using DbxWebAuth, you get back an "authorization code", which is not an access token. You need to exchange that authorization code for an access token, as shown here.

  • overjeer's avatar
    overjeer
    Helpful | Level 6
    9 years ago
    thanks mate. I will give this a go and come back to you. Thanks so much for coming back so swiftly!
  • overjeer's avatar
    overjeer
    Helpful | Level 6
    9 years ago

    That worked! :D thanks so much Greg.

     

    Also the 500 error is gone so we can close this one. Thanks again!

     

    By the by, I *had* forgotten a crucial step in the way I was authorising the app - to run: 

     

    AuthFinish

     I wrote my own Webview that was generating the token quite well but I think not running auth finish was detrimental to the process :)

     

    cheers mate!

  • Greg-DB's avatar
    Greg-DB
    Icon for Dropbox Community Moderator rankDropbox Community Moderator
    9 years ago
    We did find and resolve the issue causing the 500 late yesterday. Thanks for confirming!

About Dropbox API Support & Feedback

Node avatar for Dropbox API Support & Feedback
Find help with the Dropbox API from other developers.

The Dropbox Community team is active from Monday to Friday. We try to respond to you as soon as we can, usually within 2 hours.

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, Facebook or Instagram.

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!