I am trying to use the Google Drive API to set a Google Sheet into "Publish to Web" mode so that I can embed it on my website.
Using the Drive API in my PHP:-
// Get the API client and construct the service object.
$client = getClient();
$service = new Google_Service_Sheets($client);
$driveservice = new Google_Service_Drive($client);
/*
$copiedFile = new Google_Service_Drive_DriveFile(array('name' => 'Project plan'));
$responseBody=$driveservice->files->copy("1hAjKEox4hhlK4aoCVLuUVfTJbKPhFklG1gG9-HsGH7U", $copiedFile);
$sheet_id=$responseBody->id;
*/
$sheet_id="1tYktONmPaaxGaS5ylNn8nTzPjtdEsuYIDHakhap8Amk";
$revisions=$driveservice->revisions;
$sheetinformation =$revisions->listRevisions("1tYktONmPaaxGaS5ylNn8nTzPjtdEsuYIDHakhap8Amk");
$revisions=$sheetinformation->getRevisions();
$count=count($revisions);
$revision_id=$revisions[$count-1]->id;
$finalrevision=$driveservice->revisions->get($sheet_id,$revision_id);
$finalrevision->publishAuto=true;
$driveservice->revisions->update($sheet_id,$revision_id, $finalrevision);
die();
As far as I can tell this conforms to the Drive API specification (I really wish they hadn't removed the code examples for PHP!). However, I am getting the following error returned in the Response body:-
"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."
}
}
Any help would be appreciated!