You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在PHP Google Drive API V2中用create方法禁用sendNotificationEmails

解决PHP Google Drive API V2权限授予时停止发送通知邮件的问题

嘿,这个问题很好解决!Google Drive API的permissions.create方法默认会给被授权用户发送通知邮件,你只需要在请求参数里加一个配置项就能关闭这个行为。

修改后的代码

你只需要在permissions->create的第三个请求选项数组里,添加'sendNotificationEmail' => false参数即可。修改后的完整代码如下:

foreach($EMAILS as $cnt=>$email){ 
  $userPermission = new Google_Service_Drive_Permission(array( 
    'type' => 'user', 
    'role' => 'writer', 
    'emailAddress' => $email 
  )); 
  // 新增sendNotificationEmail参数关闭通知邮件
  $request = $driveService->permissions->create( 
    $fileId, 
    $userPermission, 
    array(
      'fields' => 'id',
      'sendNotificationEmail' => false
    )
  ); 
  $batch->add($request, 'user'); 
  $results[] = $batch->execute(); 
}

补充说明

  • sendNotificationEmail是Google Drive API V2内置的参数,默认值为true,手动设置为false就会阻止系统发送授权通知邮件。
  • 这个参数对你当前的批量请求逻辑完全兼容,不需要调整批量处理的其他代码,只需要在单个权限创建请求里配置即可。

内容的提问来源于stack exchange,提问作者Jenil Kanani

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.15 07:13:27