【发布时间】:2017-05-08 13:24:17
【问题描述】:
我的目的是能够上传 Google Drive 上已有文件的新版本。
我从 https://developers.google.com/drive/v2/reference/files/update#examples 的 PHP 示例开始。
function updateFile($fileID, $uploadFile) {
try {
$file = $this->service->files->get($fileID);
$content = file_get_contents($uploadFile);
$file = $this->service->files->update($fileID, $file, array(
'data' => $content,
));
printf("Updated File ID: %s\n", $file->getId());
} catch (Exception $e) {
echo get_class($e), ': ', $e->getMessage(), PHP_EOL;
}
}
结果我得到了
Google_Service_Exception: {
"error": {
"errors": [
{
"domain": "global",
"reason": "fieldNotWritable",
"message": "The resource body includes fields which are not directly writable."
}
],
"code": 403,
"message": "The resource body includes fields which are not directly writable."
}
}
我不明白有问题的不可写字段是什么。我唯一要更改的是文件的实际内容,而不是元数据。
有什么想法吗?
【问题讨论】:
-
这可能与 API v3 的变化有关吗?
标签: google-api google-drive-api google-apis-explorer google-php-sdk