我正在尝试使用 PHP 将文件上传到 Google Drive。
对于授权代码,我使用以下范围:
https://www.googleapis.com/auth/drive
https://docs.google.com/feeds/
https://docs.googleusercontent.com/
https://spreadsheets.google.com/feeds/
我已经收到了一个有效refresh_token
的 ,我可以随时用它来获取一个新的access_token
。
现在的问题是当我尝试使用它执行上传时access_token
(它没有过期,也没有使用)它说:
stdClass Object
(
[error] => stdClass Object
(
[errors] => Array
(
[0] => stdClass Object
(
[domain] => global
[reason] => required
[message] => Login Required
[locationType] => header
[location] => Authorization
)
)
[code] => 401
[message] => Login Required
)
)
我正在使用带有以下标题的 curl:
Array
(
[0] => Content-Type: text/plain
[1] => Content-Length: 503242
[2] => Authorization: Bearer ya29.AHES6ZRWXZkZDDi6AFV9PK2QonHp93nIfJbYqipXFT1uCsg
[3] => GData-Version: 3.0
)
和以下网址:
https://www.googleapis.com/upload/drive/v2/files?uploadType=media
CURL 命令类似于:
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HTTPHEADERS, $headers);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, file_get_contents($file));
$return = curl_exec($ch);
curl_close($ch);
任何帮助将不胜感激......在此先感谢......