cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Announcements
Want to know what we learned at IBC? Check out our learnings on media, remote working and more right here.

Discuss Dropbox Developer & API

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

Cannot get Access Token via https://api.dropboxapi.com/oauth2/token!

Cannot get Access Token via https://api.dropboxapi.com/oauth2/token!

jkdev
Explorer | Level 3

When I try to get an access Token using Fetch in JavaScript via the in the title specified endpoint, it returns this:

 

{"webSocket":null,"url":"https://api.dropboxapi.com/oauth2/token","redirected":false,"ok":true,"headers":{},"statusText":"OK","status":200,"bodyUsed":false,"body":{"locked":false}}

 

 

My Code is this:

 

    async function getInitial() {
      let dropBoxConnection = await fetch(`https://api.dropboxapi.com/oauth2/token`, {
        body: new URLSearchParams({
          code: dropToken,
          grant_type: 'authorization_code',
          redirect_uri: DropBoxData.redirect,
          client_id: DropBoxData.key,
          client_secret: DropBoxData.secret
        }),
        method: "POST"
      }).then((response) => {
        return response;
      }).catch((error) =>  {
        return new Error(error);
      });

      return await dropBoxConnection;
    }

    if(dropToken) var DropboxReturn = await getInitial();

    return new Response("Old Token: " + dropToken + ";" + " API-Response: " + JSON.stringify(DropboxReturn));

 

2 Replies 2

Greg-DB
Dropbox Staff

I see you're getting a 200 status code which should indicate that the call completed, but I don't see the actual response body here. Can you print out the response body? I can't offer help with fetch itself so you may need to refer to the fetch documentation for information on using it.

jkdev
Explorer | Level 3

I figured it out.. I used the wrong method to print out the response body. I printed out the Response, when I should've printed out Response.json().

Need more support?
Who's talking

Top contributors to this post

  • User avatar
    jkdev Explorer | Level 3
  • User avatar
    Greg-DB Dropbox Staff
What do Dropbox user levels mean?