Need to see if your shared folder is taking up space on your dropbox 👨💻? Find out how to check here.
Forum Discussion
bspindia
3 years agoHelpful | Level 7
legacy token
my token is expiring while making api calls and getting unauthorised error due to short live tokens, how to generate unexpired token
please assist
regards,
Sikandar
- 3 years agoHurray made it$ch = curl_init();curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);curl_setopt($ch, CURLOPT_POST, 1);curl_setopt($ch, CURLOPT_POSTFIELDS, "grant_type=refresh_token&refresh_token=***refreshtoken******");curl_setopt($ch, CURLOPT_USERPWD, '**AppKey' . ':' . '***AppSecret*****');$headers = array();$headers[] = 'Content-Type: application/x-www-form-urlencoded';curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);$result = curl_exec($ch);echo $result;if (curl_errno($ch)) {echo 'Error:' . curl_error($ch);}curl_close($ch);
bspindia
3 years agoHelpful | Level 7
i am trying to take code in res please correct headers, right now i am having error as invalid_request
"Content-Type":"application/json",
"Authorization":"Bearer "+dropBox.apiKey+":"+dropBox.keySecret,
}}).then(req=>req.json()).then(res=>console.log(res)).catch(error=>console.log(error))
Greg-DB
Dropbox Community Moderator
3 years agobspindia Здравко is correct; your request is not formatted properly. You should use "Basic" authorization for that particular call, not "Bearer". Also, make sure you supply the necessary parameters as shown in the documentation. Check out step 5 in section 2 of this blog post for an example to translate.
- bspindia3 years agoHelpful | Level 7i am getting the code when i manually enter url in browser, but how to get using fetch api// authorizationlet dropBox = new Object();dropBox.apiKey = 'XXXXXXXXXX';dropBox.apiSecret = 'XXXXXXXXX';"Content-Type":"application/json","client_id":dropBox.apiKey,"response_type":"code","token_access_type":"offline","state":"",}}).then(authReq=>authReq.json()).then(authRes=>{// obtain tokenconsole.log(authRes)// store token in indexedDB}).then(calldBox=>{// call api})
- Здравко3 years agoLegendary | Level 20
Hi bspindia,
You cannot call /oauth2/authorize as regular API call (or similar)! This is address you should redirect to (either explicitly or with web link) your web session to let user authenticates. So you cannot use 'fetch'. To get some of results fields (including the code) you have to "catch" it in your browser address line. 😉 Example how you can get code may be seen here and how you can get access token (short lived) may be seen here. Again, 'fetch' or any other similar method to make a web request is inapplicable in this very first step! 'fetch' is usable for all remaining API calls (regular or not).
Read the documentation with more attention to details (devil is in details 😈).
- Greg-DB3 years ago
Dropbox Community Moderator
bspindia Здравко is correct; /oauth2/authorize is a web page, not an API call. It's where you should send the user, in their web browser, to authorize your app.
- bspindia3 years agoHelpful | Level 7
ok used location.assign()
and got code in redirected url
used url searchparamaters and stored code
again i made a location.assign("")but got 400 error as Unexpected response_type request param value.
About Discuss Dropbox Developer & API
Make connections with 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!