I am trying to integrate Dropbox in my webservice. However I decided to use a direct integration instead of any APIs as I need a limited number of functions only and not used to code object orientated in PHP.
For any reason my authentication token handling is not working. I figured out, something is wrong with the basic authentifiation, as some other functions which should work with basic as well as bearer authentification do only work with the last one mentioned.
function dropboxAuthentication($code){
global $authToken;
$parameters['code']=$code;
$parameters['grant_type']="authorization_code";
$parameters['redirect_uri']="https://myurl.com/file.php";
// Create the context for the request
$context = stream_context_create(array(
'http' => array(
'method' => 'POST',
'header' => 'Authorization: {Basic '.base64_encode("my app id:my app secret").'}\r\n'.
'Content-Type: application/json\r\n',
'content' => json_encode($parameters)
)
));
// Send the request
$response = file_get_contents('https://api.dropboxapi.com/oauth2/token', FALSE, $context);
// Check for errors
if($response === FALSE){
die('Error');
}
// Decode the response
$result=json_decode($response, TRUE);
return $result['code'];
}
The file accessed after the login calls the function with the temporary code given. The temporary code is received well.
The result is always
Error
I checked the response code which is a HTTP Error 400.
Thank you very much for your support!