我在将文件上传到 Google Drive 时遇到问题,我无法上传文件。任何人都可以帮助,请回答。
以下是我上传文件时遇到的错误:
{
"error": {
"errors": [
{
"domain": "global",
"reason": "authError",
"message": "Invalid Credentials",
"locationType": "header",
"location": "Authorization"
}
],
"code": 401,
"message": "Invalid Credentials"
}
}
我已经使用驱动 SDK 注册了应用程序,并且正在使用驱动 SDK 客户端 ID。此外,我每次都使用数据库中保存的长期刷新令牌中的更新访问令牌。
代码在这里:
$fname = basename($updfile); // where $updfile is the file name with path
$turl = "https://www.googleapis.com/drive/v1/files";
$jsondata = '
{
"title": "'.$fname.'",
"mimeType":"application/zip",
"description":"The mailchimp data export to google drive."
}';
$headers = 'Host: www.googleapis.com'."\r\n";
$headers .= 'Authorization: Bearer '.$access_token."\r\n"; // $access_token is token generating everytime from refresh token
$headers .= 'Content-Type: application/json'."\r\n";
$headers .='Content-Length: '.strlen($jsondata)."\r\n";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $turl);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $jsondata);
curl_setopt($ch, CURLOPT_HTTPHEADER, array($headers));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$response = curl_exec($ch);
curl_close($ch);
如果有人对此有解决方案或建议,请回复/回答。提前致谢。