我想使用PHP API创建google doc excel表格的副本。我可以看到Java代码,但完全没有PHP代码:(
实际上,我已经在Google驱动器上有了一个excel工作表,我想在网站上显示它,我已经成功完成了,但是问题是每个人都可以看到相同的文件,并且如果一个用户同时更改了该文件,而同一用户可以看到更改已同步到Google云端硬盘。
所以我认为解决方案是,我可以创建工作表的副本并通过PHP API向每个用户显示不同的2个副本。
================ >>
已编辑代码
function copyFile($service, $originFileId, $copyTitle) { $copiedFile = new Google_DriveFile(); $copiedFile->setTitle($copyTitle); try { $arr['convert'] = false; $arr['visibility'] = 'default'; return $service->files->copy($originFileId, $copiedFile,$arr); } catch (Exception $e) { print "An error occurred: " . $e->getMessage(); } return NULL; } function insertPermission($service, $fileId, $value, $type, $role) { $newPermission = new Google_Permission(); $newPermission->setValue($value); $newPermission->setType($type); $newPermission->setRole($role); try { return $service->permissions->insert($fileId, $newPermission); } catch (Exception $e) { print "An error occurred: " . $e->getMessage(); } return NULL; } function updateRevision($service, $fileId, $revisionId) { try { // First retrieve the revision from the API. $revisions = $service->revisions; $revision = $revisions->get($fileId, $revisionId); echo '<pre>';print_r($revision); $revision->setPinned(true); return $revisions->update($fileId, $revisionId, $revision); } catch (Exception $e) { print "An error occurred: " . $e->getMessage(); } return NULL; } function updateRevision1($service, $fileId, $revisionId) { $patchedRevision = new Google_Revision(); $patchedRevision->setPublished(true); $patchedRevision->setPublishAuto(true); $patchedRevision->setPublishedOutsideDomain(true); try { return $service->revisions->patch($fileId, $revisionId, $patchedRevision); } catch (Exception $e) { print "An error occurred: " . $e->getMessage(); } return NULL; } require_once 'google-api-php-client/src/Google_Client.php'; require_once 'google-api-php-client/src/contrib/Google_DriveService.php'; $client = new Google_Client(); // Get your credentials from the console $client->setClientId('clientid'); $client->setClientSecret('secret'); $client->setScopes(array('https://www.googleapis.com/auth/drive')); $client->setRedirectUri('redirecturi'); $service = new Google_DriveService($client); if(!isset($_GET['code']) ) { $authUrl = $client->createAuthUrl(); header('location: '.$authUrl ); die; } else{ $authCode = $_GET['code']; // Exchange authorization code for access token $accessToken = $client->authenticate($authCode); $client->setAccessToken($accessToken); $new_file = copyFile($service,'fileid','Baby Schema'); echo 'file=<pre>';print_r($new_file); $permission = insertPermission($service,$new_file['id'],'me','anyone','writer'); echo 'permission=<pre>';print_r($permission); $revision = updateRevision1($service, $new_file['id'], '1'); echo 'pub=<pre>';print_r($revision); }
代码在工作上绝对完美,但它没有按照我的意愿进行。
上面的代码正在执行这些任务
1) I have one spreadsheet on [email protected] 2) I am creating copy when [email protected] login to my abc.com website. 3) I am setting copy to be public on web. 4) Making copy to be published on web.
现在我有问题。
1) In the spreadsheet there are 5 sheets out of them 2 are editable and rest 3 are protected so no one can see my formulas. 2) When copy is created by [email protected] then he becomes the owner of file while file is on [email protected] while I want Owner to be bhuvneshgupta not bhuvnesh.gupta because I don't want to show formulas to any one not even bhuvnesh.gupta when file is opened on web. 3) I want to protect 3 sheets of spreadsheet to everyone.
我正在使用这种方式在网络上呼叫spreadhseet。
<iframe width="100%" height="600" src="https://docs.google.com/spreadsheets/d/fileid/edit?usp=sharing;&rm=minimal"></iframe>
[请帮助我,这是我项目的最后一点。
请帮助我。
提前感谢!
我想使用PHP API创建google doc excel表格的副本。我可以看到Java代码,但根本没有PHP的代码:(实际上,我已经在google驱动器上有了一个excel表格,我想在网站上显示它,我是...
Google驱动器API参考中确实包含用于文件复制的PhP代码。