cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Announcements
We want to hear from you. What do you use Dropbox for?
Close

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: 
Highlighted

Javascript SDK to authorize user and get access token

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
Highlighted

Re: Javascript SDK to authorize user and get access token

Dropboxer
Dropboxer

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.

Work Smarter with Dropbox

The way we work is changing. Share and discover new ways to work smarter with Dropbox in our community.

Sound good? Let's get started.
Who's talking

Top contributors to this post

What do Dropbox user levels mean?
Need more support?