php - Google API 为用户订阅日历
问题描述
我的 PHP 代码使用服务帐号在 G Suite/Google Workspace 中创建新用户。这部分工作正常,但我想自动为新用户订阅我们的一些标准办公日历。当我运行以下代码时,日历将添加到服务帐户的列表中,而不是新用户。
$service = new Google_Service_Calendar($client);
$calendarListEntry = new Google_Service_Calendar_CalendarListEntry();
$calendarListEntry->setId("CalendarID");
$calendarListEntry = $service->calendarList->insert($calendarListEntry);
无论如何要插入另一个用户日历列表吗?
解决方案
服务帐户有自己的 google 日历帐户,您执行的任何操作都将在服务帐户 google 日历帐户上执行。
但是,如果您想在声明客户时模拟用户,则需要确保添加主题或您希望模拟的人。
putenv('GOOGLE_APPLICATION_CREDENTIALS=/path/to/service-account.json');
$client = new Google\Client();
$client->useApplicationDefaultCredentials();
Set the scopes required for the API you are going to call
$client->addScope(Google\Service\CALENDAR::CALENDAR);
$client->setSubject($user_to_impersonate);
推荐阅读
- amazon-emr - 有没有办法让 Step Functions 输入值进入 EMR step Args
- laravel - 在 Laravel 6 中对子查询使用 addSelect 时出错
- asp.net-core - 使用百分比语法从 appsettings.json 获取设置
- sql-server - T-SQL 监控 SQL 工作线程
- python - 使用 python 积分器检查收敛
- python - 使用 Bitnami wordpress-multisite 部署 GCP VM 时如何防止出现“模板与 Python3 不兼容”警告?
- node.js - 在 chaijs 中执行 GraphQL Mutation
- php - TYPO3 v9.5.11 Extbase:将ContainerClass生成的ServiceObject注入Repository
- docker - 如何区分标准输出日志?
- testing - 如何使用 cypress.io 处理 PayPal 弹出窗口中的元素