【发布时间】:2015-02-18 08:22:02
【问题描述】:
我正在尝试更新文件的内容。使用PHP函数:
function updateFile($service, $fileId, $newTitle, $newDescription, $newMimeType, $newFileName, $newRevision) {
try {
// First retrieve the file from the API.
$file = $service->files->get($fileId);
// File's new metadata.
$file->setTitle($newTitle);
$file->setDescription($newDescription);
$file->setMimeType($newMimeType);
// File's new content.
$data = file_get_contents($newFileName);
$additionalParams = array(
'newRevision' => $newRevision,
'data' => $data,
'mimeType' => $newMimeType
);
// Send the request to the API.
$updatedFile = $service->files->update($fileId, $file, $additionalParams);
return $updatedFile;
} catch (Exception $e) {
print "An error occurred: " . $e->getMessage();
}
}
....
$data = retrieveAllFiles($service);
$fileName = 'test.txt';
$mimeType = mime_content_type('./'.$fileName);
$res = updateFile($service, $data[0]['id'], $data[0]['title'], 'update', $mimeType, $fileName, true);
我正在尝试添加一个文本文件行“测试字符串”。函数更新数据文件(description、lastModifyingUser...),但文件内容保持不变。谁能告诉我怎么了?
【问题讨论】:
-
尝试在 API 资源管理器中发送相同的请求,看看您是否能够正确看到更新。这是 API 浏览器的链接:developers.google.com/apis-explorer/#p
标签: php google-app-engine google-drive-api