【问题标题】:Add multiple users to Google Drive folder through Drive API通过 Drive API 将多个用户添加到 Google Drive 文件夹
【发布时间】:2017-04-25 17:31:35
【问题描述】:

我有一个电子邮件地址列表,并希望通过 Google Drive API 授予他们访问 Google Drive 文件夹的权限。我将电子邮件地址作为变量传递并传递给创建权限数组。但是发生错误,表明电子邮件地址无效。我使用 print_r() 检查了电子邮件地址,它是正确的。以下是我在PHP中使用的代码。

$batch = $driveService->createBatch();

// read files containing multiple email address
$myfile = fopen("emaillist.csv","r") or die("Unable to open file!");
$emailList = fread($myfile, filesize("emaillist.csv"));
fclose($myfile);    
$emailListArray = explode(";", $emailList);

$index = 1;
foreach($emailListArray as $email) {

  $userPermission = new Google_Service_Drive_Permission(array(
    'type' => 'user',
    'role' => 'reader'
    'emailAddress' => $email
  ));

  $request = $driveService->permissions->create($fileId, $userPermission, array('fields' => 'id'));
  $batch->add($request, 'user'.$index);

  $index++;
}
$results = $batch->execute();

任何人都可以指导我的代码有什么问题。谢谢!

【问题讨论】:

    标签: php google-drive-api


    【解决方案1】:

    我发现我需要修剪电子邮件地址以删除多余的空格。 IE。 'emailAddress' => $email 之后,它就可以工作了。

    【讨论】:

    • 更正:即。 'emailAddress' => 修剪($email)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-07-04
    • 1970-01-01
    • 1970-01-01
    • 2020-08-11
    • 2020-03-10
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多