We’re Still Here to Help (Even Over the Holidays!) - find out more here.
Forum Discussion
GIS_questions
4 years agoExplorer | Level 4
Error when attempting to get an access token using refresh token
I keep encountering the same error when I attempt to use my refresh token, client id and client secret to get a new access token in my javascript code:
" Error in call to API function "files/upload...
GIS_questions
4 years agoExplorer | Level 4
Hi Greg,
Thank you so much for your reply!
Do you have any basic examples of doing this through javascript? I've been able to get the refresh token using curl, but I haven't had the same luck with my code. I've looked at the documentation on the OAuth guide and authorization documentation but I can't get the Javascript to function.
Thank you!
Greg-DB
Dropbox Community Moderator
4 years agoGIS_questions As Здравко referred to, I recommend using the official Dropbox JavaScript SDK if possible, as it will do much of the work for you. Alternatively, it may also just serve as a good example even if you can't use it.
- GIS_questions4 years agoExplorer | Level 4
Hi Greg-DB,
Would you mind taking a look at this code and telling me where I'm going wrong? Currently I'm getting a 400 error regarding the bearer. I am using the access code for the bearer, though I don't know if it has to be the access token? The problem there being that I have to use this code to get the temporary access token, so I don't know how to request the access token without a preexisting access token, if that makes any sense? I'm using the url: https://api.dropbox.com/oauth2/token. I've also tried this without the Authorization request header, and with a grant_type of client_credentials.
Thank you so much for your help!
- Greg-DB4 years ago
Dropbox Community Moderator
Whenever you get an error like this 400 error response, be sure to print out the response body as it will generally contain a more useful error message. What does it contain in this case?
Looking at your code though, I see you're attempting the step where you call /oauth2/token with the existing refresh token to get a new short-lived access token. That corresponds to the "refresh token request" example in the documentation for /oauth2/token. There are a few things that look wrong in your code as compared to that:
- you should not be supplying a Bearer token/code; this step does not require or accept an access token or authorization code
- you should not be setting the Content-Type to application/json or JSON-encoding your parameters; this OAuth endpoint expects the parameters as application/x-www-form-urlencoded POST parameters
About 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!