Forum Discussion

Abdullah S.1's avatar
Abdullah S.1
New member | Level 2
11 years ago

How to check validity of access token in java code

How to check validity of access token in java code before using it?

2 Replies

Replies have been turned off for this discussion
  • Just try it and look for a 401 response to indicate an auth problem.

    I might use the /account/info endpoint for this (since it pretty much can't fail for any other reason).

    But note that the access token could be revoked at any time, so you'll still need to handle the case where the call you're actually making fails. E.g., this is an anti-pattern.

    if (isValid(token)) {
        // What if the token gets revoked right here? After you checked but before you upload the file?
        uploadFile(..., token);
    }
    

    Since the check doesn't really save you having to do the error handling, you may as well just try to upload the file and handle the 401 error if it occurs.

  • Abdullah S.1's avatar
    Abdullah S.1
    New member | Level 2
    11 years ago

    I've 2 programs one to get the token and serialize it and the other is to deserialize it and use it maybe on another pc
    i want the first one to read the .ser file that generated from the last use and check if it is valid or not
    so i have two solutions now
    1- make the first program create small file and test the access token to upload it and then delete it if it is uploaded.
    2- make the first program get new access token every time and serialize it.
    thanks for your reply :)

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!