Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/251.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何设置;任何有链接的人;可以通过API在Google电子表格上编辑权限。首选PHP_Php_Google Sheets Api - Fatal编程技术网

如何设置;任何有链接的人;可以通过API在Google电子表格上编辑权限。首选PHP

如何设置;任何有链接的人;可以通过API在Google电子表格上编辑权限。首选PHP,php,google-sheets-api,Php,Google Sheets Api,我有以下设置文件权限的代码,如何将其更改为具有“链接可以编辑”权限的任何人 function setPermissions($fileId, $email){ $client2 = new \Google_Client(); $client2->setApplicationName('Give permissions'); $client2->setScopes([\Google_Service_Drive::DRIVE]); $client2->

我有以下设置文件权限的代码,如何将其更改为具有“链接可以编辑”权限的任何人

function setPermissions($fileId, $email){
    $client2 = new \Google_Client();
    $client2->setApplicationName('Give permissions');
    $client2->setScopes([\Google_Service_Drive::DRIVE]);
    $client2->setAccessType('offline');
    $client2->setAuthConfig('credentials.json');
    $tokenPath = 'token.json';
    if (file_exists($tokenPath)) {
        $accessToken = json_decode(file_get_contents($tokenPath), true);
        $client2->setAccessToken($accessToken);
    }
    $client2->setPrompt('select_account consent');
    $service2 = new Google_Service_Drive($client2);
    $newPermission = new Google_Service_Drive_Permission();
    $newPermission->setEmailAddress($email);
    $newPermission->setType('user');
    $newPermission->setRole('writer');
    $service2->permissions->create($fileId, $newPermission);
}


我相信你的目标和你的处境如下

  • 您希望使用googleapis for php以“具有链接的任何人”作为编写者来创建权限
  • 您可以使用驱动器API获取和放置文件
修改点:
  • 在这种情况下,请将
    任何人
    设置为
    类型
    ,并删除
    设置电子邮件地址($email)
修改脚本: 修改脚本时,请按以下方式修改

发件人: 致: 参考:

    • 我相信你的目标和处境如下

      • 您希望使用googleapis for php以“具有链接的任何人”作为编写者来创建权限
      • 您可以使用驱动器API获取和放置文件
      修改点:
      • 在这种情况下,请将
        任何人
        设置为
        类型
        ,并删除
        设置电子邮件地址($email)
      修改脚本: 修改脚本时,请按以下方式修改

      发件人: 致: 参考:
      $newPermission = new Google_Service_Drive_Permission();
      $newPermission->setEmailAddress($email);
      $newPermission->setType('user');
      $newPermission->setRole('writer');
      
      $newPermission = new Google_Service_Drive_Permission();
      $newPermission->setType('anyone');
      $newPermission->setRole('writer');