Need to see if your shared folder is taking up space on your dropbox 👨💻? Find out how to check here.
Forum Discussion
FSUInnovation
6 years agoExplorer | Level 4
header array invalid request for token auth php
I have been trying to get the header array for my php curl working. This is the structure of it.
$http_headers = array(
"Authorization: " . base64_encode($app_key . ":" . $app_secret),
"Content-T...
- 6 years ago
You should send them as POST parameters, encoded using "application/x-www-form-urlencoded", not headers. Here's a basic example I just put together for calling /oauth2/token using curl in PHP:
$app_key = "<APP_KEY>"; $app_secret = "<APP_SECRET>"; $headers = array("Authorization: Basic " . base64_encode($app_key . ":" . $app_secret), "Content-Type: application/x-www-form-urlencoded"); $authorization_code = "<AUTHORIZATION_CODE>"; $redirect_uri = "<REDIRECT_URI>"; $params = array("code" => $authorization_code, "grant_type" => "authorization_code", "redirect_uri" => $redirect_uri); $ch = curl_init('https://api.dropboxapi.com/oauth2/token'); curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($params)); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); $response = curl_exec($ch); echo $response; if (curl_errno($ch)) { echo 'Error:' . curl_error($ch); } curl_close($ch);
Greg-DB
Dropbox Community Moderator
6 years agoWhen using "Basic" authorization, your "Authorization" header value should start with the string "Basic ". So, that line should look like:
"Authorization: Basic " . base64_encode($app_key . ":" . $app_secret),
Also, note that the /oauth2/token endpoint is based on the OAuth spec and doesn't work like the other Dropbox API endpoints. Specifically, it doesn't take a "Dropbox-API-Arg" header. You should be specifiy those parameters as 'application/x-www-form-urlencoded' POST parameters, not JSON in a header or body.
FSUInnovation
6 years agoExplorer | Level 4
Do the other parameters need to be in a assosiative array appended to the Content Type element like I would do with the API Args, or do I need to post those parameters like this: "code: " . $code, ... ?
- Greg-DB6 years ago
Dropbox Community Moderator
You should send them as POST parameters, encoded using "application/x-www-form-urlencoded", not headers. Here's a basic example I just put together for calling /oauth2/token using curl in PHP:
$app_key = "<APP_KEY>"; $app_secret = "<APP_SECRET>"; $headers = array("Authorization: Basic " . base64_encode($app_key . ":" . $app_secret), "Content-Type: application/x-www-form-urlencoded"); $authorization_code = "<AUTHORIZATION_CODE>"; $redirect_uri = "<REDIRECT_URI>"; $params = array("code" => $authorization_code, "grant_type" => "authorization_code", "redirect_uri" => $redirect_uri); $ch = curl_init('https://api.dropboxapi.com/oauth2/token'); curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($params)); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); $response = curl_exec($ch); echo $response; if (curl_errno($ch)) { echo 'Error:' . curl_error($ch); } curl_close($ch);
About 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!