更新时间:2022-05-19 22:04:38
以下是完成此工作的步骤:
Here are the steps to follow to make this work:
在您的服务帐户中启用全域委派
1 - 为您的服务帐户提供日历范围
2 - 您的用户需要具有 Service Account Token Creator 角色
3 - 在您要模拟的帐户中创建日历
服务帐户没有日历,因此您必须创建自己的日历
Service accounts don't have calendars so you have to create your own calendar
创建谷歌客户端
代码示例:(我使用的是 PHP,但我假设其他语言非常相似,因此您可以以此为指导)
Code sample: (I used PHP but I assume that other languages are very similar so you can use this as guideline)
请注意,使用某些电子邮件进行 IMPERSONALIZATION 至关重要.否则,将保留 403 错误,将其用于身份验证,有关详细信息,请参阅 Maksym Kalin 响应.
$google_client = new Google_Client();
$google_client->setAuthConfig($LOCATION_OF_JSON_KEY);
$google_client->setAccessType( 'offline' );
$google_client->setSubject('EmailToImpersonate@SomeAddress.com');
$google_client->setApplicationName("YourApplicationName");
$google_client->setScopes([Google_Service_Calendar::CALENDAR, Google_Service_Calendar::CALENDAR_EVENTS]);
与受邀者一起创建活动 :) 并享受!
注意: 通过这种方法,您可以创建活动并邀请人们加入.请记住 G Suite 的限制 https://support.google.com/a/answer/2905486 因此,如果您想创建许多事件,则需要有一个带有日历池的服务帐户池.
Note: With this approach you can create events and invite people to it. Keep in mind the limits of the G Suite https://support.google.com/a/answer/2905486 so if you want to create many events you will need to have a pool of service accounts with a pool of calendars.