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

Forum Discussion

bffy_smmmers's avatar
bffy_smmmers
Helpful | Level 5
5 years ago
Solved

dbx.auth not working / getAccessTokenFromCode giving 400 response?

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

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

    I'm not sure I follow your message, but you should specify it in both places. The /oauth2/authorize page redirect_uri parameter specifies where to send the user after they authorize the app, and the 'redirectUri' you pass to 'getAccessTokenFromCode' is just a string sent up in a /oauth2/token API call to verify that it matches.

12 Replies

Replies have been turned off for this discussion
  • Greg-DB's avatar
    Greg-DB
    Icon for Dropbox Community Moderator rankDropbox Community Moderator
    5 years ago

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

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!