Dropbox API Support & Feedback
Find help with the Dropbox API from other developers.
I'm trying to access the `getAccessTokenFromCode` method and I keep receiving a 400 error. On top of that, I can't seem to write the code and get it to work in the way it's written in the Auth example from the JavaScript SDK. `dbx.auth` does not work for me whether I construct an instance of Dropbox or DropboxAuth.
When i call `dbx.GetAccessTokenFromCode(redirectURI, code)`, I get a 400 response. I'm using the latest version (9.2.0). Furthermore, I read that `getAccessTokenFromCode` accepts null as a value in redirect uri as of version 5.0 and that doesn't work for me here either. Any help is so much appreciated. Thanks!
Example (Leaving a lot out since all I want to show is that token.result.refresh_token doesn't exist for me, just token.result.
const dbx = new Dropbox(config);
dbx.auth
.getAccessTokenFromCode(redirectUri, code)
.then(token => {
console.log(`Token Result:${JSON.stringify(token)}`);
dbx.auth.setRefreshToken(token.result.refresh_token);
dbx
.usersGetCurrentAccount()
.then(response => {
console.log('response', response);
})
What I have to do is use the DropboxAuth class - which still doesn't work. (I'm using TypeScript, if it matters)
const dbx = new DropboxAuth(config)
try {
const data = await dbx.getAccessTokenFromCode('some redirectURL',code)
} catch (err){
console.log(err.message)
}
That's correct, that parameter isn't currently implemented in the Dropbox JavaScript SDK, but I'll be sure to pass this along as a feature request. You can add it to the /oauth2/authorize URL in your app's own code though, by modifying the URL returned by getAuthenticationUrl.
@Greg-DB Would you be able to expand on how that exactly gets done? Thanks!
For example, where authUrl is the URL you got from getAuthenticationUrl, you can modify it like this:
var url = new URL(authUrl);
var urlParams = new URLSearchParams(url.search);
urlParams.set('force_reapprove', 'true');
url.search = urlParams;
console.log(url.href);
Hi there!
If you need more help you can view your support options (expected response time for a ticket is 24 hours), or contact us on X or Facebook.
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!