cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Announcements
Want to learn some quick and useful tips to make your day easier? Check out how Calvin uses Replay to get feedback from other teams at Dropbox here.

Dropbox API Support & Feedback

Find help with the Dropbox API from other developers.

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Javascript SDK to authorize user and get access token

Javascript SDK to authorize user and get access token

namiqismayil
Helpful | Level 5

Hi,

I am trying to get access token after Autharization. 

So on button click I redirect user to

 https://www.dropbox.com/oauth2/authorize?client_id=<APP_KEY>&response_type=code 

So user goes through the steps and authorize the app but it goes to a page like this II

image.png

I use Window.open with redirect url.

window.open(url,redirectURL );

I have a feeling I am not constructing redirect url properly. Can you please provide me with an example of window.open with proper url?

What am I doing wrong here?

1 Reply 1

Greg-DB
Dropbox Staff

If you're using the official Dropbox API v2 JavaScript to integrate with Dropbox in a JavaScript app, you should use the supplied 'getAuthenticationUrl' method to build your authorization URL, which will contain whatever redirect URI value you supply. There's a working auth example included with the SDK here. (Instructions for running the examples can be found here.)

On this line, you call the getAuthenticationUrl method, supplying what you want your redirect URI to be. It gives back the full /oauth2/authorize URL, which is where you should send the user. In the example it does so by giving them a link set to that URL so they can click on it. I expect you can alternatively just pass it to window.open though. That would look like:

window.open(dbx.getAuthenticationUrl(redirectUri));

Once the user authorizes the app, Dropbox will redirect them to the specified redirect URI. In the example, the access token is retrieved from the URL fragment here.

Need more support?
Who's talking

Top contributors to this post

  • User avatar
    Greg-DB Dropbox Staff
What do Dropbox user levels mean?