How to set creating google doc in gdrive using PHP as read only file -
i creating txt/html
file in google drive document using google drive sdk. code creates document. question is possible can set file permission read-only
file?
this code in creating document,
$mkfile = $this->_service->files->insert($file, array('data' => $subcontent, 'mimetype' => 'text/html', 'convert' => true));
you can use permissions.patch update permissions file after has been inserted. there bug in api doesn't allow set permissions @ time insert file. have patch them after file has been placed on drive.
code ripped documentation link above.
/** * patch permission's role. * * @param google_service_drive $service drive api service instance. * @param string $fileid id of file update permission for. * @param string $permissionid id of permission patch. * @param string $newrole value "owner", "writer" or "reader". * @return google_servie_drive_permission patched permission. null * returned if api error occurred. */ function patchpermission($service, $fileid, $permissionid, $newrole) { $patchedpermission = new google_service_drive_permission(); $patchedpermission->setrole($newrole); try { return $service->permissions->patch($fileid, $permissionid, $patchedpermission); } catch (exception $e) { print "an error occurred: " . $e->getmessage(); } return null; }
Comments
Post a Comment