1

l try to get access token uses javascript fetch in the next way:

fetch('https://api.dropboxapi.com/oauth2/token', {
method: 'POST',
code: AUTHORIZATION_CODE,
grant_type: 'authorization_code',
redirect_uri: `${REDIRECT_URI}${window.location.pathname}`,
headers: {
'Content-Type': "application/x-www-form-urlencoded"
},
CLIENT_ID: CLIENT_SECRET
})
.then(res => res.json())
.then(data => console.log('access data =>', data))
.catch(err => console.log('access err =>',err));

I receive AUTHORIZATION_CODE after successful redirecting from "https://www.dropbox.com/oauth2/authorize..." domain.

But I have an err like

{"error_description": "No auth function available for given request", "error": "invalid_request"}

What am I doing wrong? Because I follow curl request example from here: https://www.dropbox.com/developers/documentation/http/documentation#oauth2-token

curl https://api.dropbox.com/oauth2/token \
    -d code=<AUTHORIZATION_CODE> \
    -d grant_type=authorization_code \
    -d redirect_uri=<REDIRECT_URI> \
    -u <APP_KEY>:<APP_SECRET>

Thanks!

user257924
  • 11
  • 1
  • -d corresponds to the curl request body so in fetch you'll need to add those properties to the request body that you send to the dropbox API. https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API/Using_Fetch – dwosk Oct 02 '20 at 22:41
  • I put all creds to the body of fetch, but I still got an err. { method: 'POST', headers: { 'Content-Type': 'application/x-www-form-urlencoded', 'Authorization': Basic ${CLIENT_ID}:${CLIENT_SECRET} }, body: JSON.stringify(data) } All variables is tested by debugger and have correct value....but I haven't got why am I still have this issue. – user257924 Oct 03 '20 at 20:31
  • [Cross-linking for reference: https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/Can-t-get-access-token-uses-javascript-fetch-request/m-p/458596#M23601 ] – Greg Oct 05 '20 at 15:13

0 Answers0