Hi,
I am trying to obtain an acces token by converting the authorization code. I followed both documentation available in the following links:
https://www.dropbox.com/developers-v1/core/docs#oa2-token
https://blogs.dropbox.com/developers/2013/07/using-oauth-2-0-with-the-core-api/
This is the code I am runing after being redirected from Dropbox page:
<?php
if (isset($_GET['code'])) {
echo 'UserCode -> ' . $_GET['code'];
$ch = curl_init();
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/x-www-form-urlencoded'));
curl_setopt($ch, CURLOPT_URL, "https://api.dropboxapi.com/oauth2/token");
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query(array('code'=> $_GET['code'], 'client_id' => "5n5**********aw", 'client_secret' => "zq**********tn8", 'grant_type' => $_GET['code'], 'redirect_uri' => 'http://localhost/optiSurface-dropbox/login.php')));
$response = curl_exec($ch);
echo '<pre>';
var_dump($response);
echo '</pre>';
}else{
header('Location: http://localhost/optiSurface-dropbox/curl-auth1.php');
}
However, I am receiving a error message as follow:
string(154) "{"error_description": "\"grant_type\": got \"L22mWRF0R0AAAAAAAAAGt4o3aW761b9KrBSPgX6OugA\", expecting \"authorization_code\"", "error": "invalid_request"}"As the error message says, it was expecting the authorization code. I am unsure what variable/data to use in this parameter.
Reading the documentation, I noted that is the same value from code attribute:
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>
How can I fix this problem?
Thank you in advance!