1
我試圖使用Google Drive API將Google工作表設置爲「發佈到Web」模式,以便我可以將其嵌入到我的網站中。使用Drive API(PHP)在Google電子表格中設置「發佈到網絡」
在我的PHP使用驅動器API: -
// 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();
據我可以告訴這符合驅動器API規範(我真的希望他們沒有去除PHP代碼示例!)。但是,我收到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."
}
}
任何幫助,將不勝感激!
參考此[SO帖子](https://stackoverflow.com/questions/38533957/google-sheets-api-how-to-publish-to-web-for-embeddable-sheet),你可以嘗試刪除finalrevision參數?似乎只使用了fileId和revisionId的示例。 – noogui