php - Invalid Credentials - Google Drive API
one text
The below api call always returns invalid credentials
$ch = curl_init();
$fileId = 'myfile_id';
$key = 'apikey';
$accessToken = 'access_token'
curl_setopt($ch, CURLOPT_URL, 'https://www.googleapis.com/drive/v2/files/'.$fileId.'?key='.$key);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'GET');
curl_setopt($ch, CURLOPT_ENCODING, 'gzip, deflate');
$headers = array();
$headers[] = 'Authorization: Bearer '.$accessToken;
$headers[] = 'Accept: application/json';
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$result = curl_exec($ch);
print_r($result);
if (curl_errno($ch)) {
echo 'Error:' . curl_error($ch);
}
curl_close($ch);
Response
{ "error": { "errors": [ { "domain": "global", "reason": "authError", "message": "Invalid Credentials", "locationType": "header", "location": "Authorization" } ], "code": 401, "message": "Invalid Credentials" } }
I am calling the api immediatly after recieivng the access token. So I am sure that it is not expired and the api key is also correct.
Do anyone have any idea about this ?
Source