cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Announcements
What’s new: end-to-end encryption, Replay and Dash updates. Find out more about these updates, new features and more here.

Dropbox API Support & Feedback

Find help with the Dropbox API from other developers.

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

header array invalid request for token auth php

header array invalid request for token auth php

FSUInnovation
Explorer | Level 4
Go to solution

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-Type: application/x-www-form-urlencoded",
	"Dropbox-API-Arg: " . json_encode(array(
	'code' => $code,
	'grant_type' => 'authorization_code',
	'redirect_url' => 'http://localhost:8080/FSUInnovation/ResumeUpload.php'	
)));

I get this error:

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

I don't know what particular syntax issue is causing a problem for this particular request. I tried to base it off of my curl for file upload and download.

1 Accepted Solution

Accepted Solutions

Greg-DB
Dropbox Staff
Go to solution

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);

View solution in original post

3 Replies 3

Greg-DB
Dropbox Staff
Go to solution

When 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
Explorer | Level 4
Go to solution

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
Dropbox Staff
Go to solution

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);
Need more support?
Who's talking

Top contributors to this post

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