I created one folder and inside that folder I've created 2 text files, with some text inside. I can also list the files and get the text in them without problems. Now I am trying to update the text inside of that files, but I am always getting this error:
"domain": "global",
"reason": "fieldNotWritable",
"message": "The resource body includes fields which are not directly writable."
I created a function similar to the one presented in https://developers.google.com/drive/v2/reference/files/update.
I used this example because in version v3, Google don't present any example, and I can't find anything that can help me in this. My function is below.
function updateFile ($service, $fileId, $newTitle, $newDescription, $newMimeType, $text) {
try {
// First retrieve the file from the API.
$file = $service->files->get($fileId);
// File's new metadata.
$file->setName($newTitle);
$file->setDescription($newDescription);
$file->setMimeType($newMimeType);
// File's new content.
$additionalParams = array(
'data' => $text,
'uploadType' => 'media'
);
// Send the request to the API.
$updatedFile = $service->files->update($fileId, $file, $additionalParams);
return $updatedFile;
} catch (Exception $e) {
print "An error occurred: " . $e->getMessage();
}
}
Thank you in advance.