php - 凭据无效 - Google Drive API
问题描述
下面的 api 调用总是返回无效的凭据
$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);
回复
{ "error": { "errors": [ { "domain": "global", "reason": "authError", "message": "Invalid Credentials", "locationType": "header", "location": "Authorization" } ], "code": 401, "message": "Invalid Credentials" } }
我在收到访问令牌后立即调用 api。所以我确定它没有过期并且api密钥也是正确的。
有人对此有任何想法吗?
解决方案
推荐阅读
- google-cloud-functions - ImportError:在 Google Cloud Functions 中并排使用两个模块时,尝试在没有已知父包的情况下进行相对导入
- python - Python 3.8.2 / 2.7.9 cannot output UTF-8?
- javascript - 如果 array[0] = undefined Angular ngFor 什么也不渲染
- ios - 硬编码动画或动画视频文件哪个更有效(性能方面)?
- java - 如何处理为“/api”映射的这种不明确的处理程序方法
- javascript - 我可以从缓存中加载后退按钮吗?
- python - 如何按正确的顺序对月份进行排序 Jan-Dec Pandas
- heroku - 既然 Heroku SendGrid 集成需要双重身份验证,我该如何升级它们?
- flutter - 如何根据我的选择更改控制器类中的列表?
- android - 底部导航元素在键入时移动位置