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

Forum Discussion

solsubzero's avatar
solsubzero
Helpful | Level 6
7 years ago
Solved

How to use oauth2 for dropbox via Javascript/HTML

Currently I am using the below code, but either No 'Access-Control-Allow-Origin' header or error 400 comes up everytime. I have looked for guides about No 'Access-Control-Allow-Origin' header, but ha...
  • Greg-DB's avatar
    Greg-DB
    7 years ago

    To get user information, such as their name or Dropbox account ID, you should use the /2/users/get_current_account API endpoint. (That's usersGetCurrentAccount in the official Dropbox JavaScript SDK.)

    In order to make that API call though, you first need an access token for the user. You can get an access token for the user by sending them through the OAuth app authorization flow (details and links in my previous comment). That involves sending them to the Dropbox web page where they can choose whether or not to authorize your app. Unlike actual API calls, such as /2/users/get_current_account, that step on the www.dropbox.com/oauth2/authorize web page cannot be done programmatically via ajax.

    Regarding the issues you mentioned with the 'fetch' line, note that that example is for Node.js. If you're running in front-end browser JavaScript, that won't work. (There's more information on setting up different environments here.)

    So, the basic flow would be something like this:

    1. The user arrives at your app's web page.
    2. Your app sends the user to the Dropbox app authorization web page.
    3. The user approves your app.
    4. Dropbox sends the user back to your app's web page.
    5. Your app receives the resulting access token.
    6. Your app uses the access token to make Dropbox API calls as needed, e.g., to retrieve the Dropbox account information.

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!