You might see that the Dropbox Community team have been busy working on some major updates to the Community itself! So, here is some info on what’s changed, what’s staying the same and what you can expect from the Dropbox Community overall.
Forum Discussion
FSUInnovation
5 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...
- 5 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);
FSUInnovation
Explorer | 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-DB
5 years agoDropbox Staff
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.
5,882 PostsLatest Activity: 11 hours agoIf 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 or Facebook.
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!