将事件插入到我自己的主日历之外的其他日历-404找不到错误


insert event to other calendars than my own primary one - 404 Not Found Error

我需要将事件插入到不属于我(其他用户)的多个日历中。它不必在一个命令中。。。

为了测试谷歌日历API,我使用"插入"将新事件添加到我自己的日历中,效果很好:

    // Create service from client
require_once "google-api-php-client-master/src/Google/Client.php";
require_once "google-api-php-client-master/src/Google/Service.php";
$client = new Google_Client();
$client->addScope("https://www.googleapis.com/auth/calendar");
$client->setAccessToken(htmlspecialchars_decode(get_access_token()));
$event = new Google_Service_Calendar_Event();
$event->setSummary($bean->name);
$event->setLocation($bean->location);
$event->setDescription($bean->description);
...
...
$service = new Google_Service_Calendar($client);
$createdEvent = $service->events->insert($user->google_cal_id_c, $event);

问题是,当我以我的同事日历id(我从他的日历设置中获取)为参数操作"插入"并试图将事件插入他的日历时,我得到"404未找到"错误。

更新:

我注意到,当同事与我共享日历时,只有这样我才能插入活动。这是否意味着我所有的60名同事都需要与我的(主要)同事分享他们的日历因为我真的不想那样难道我不能把事件添加到不与我共享的日历中吗?

最简单的方法是获取每个同事的访问令牌并使用这些令牌进行身份验证。然而,当你不想单独要求每个人的访问令牌时,有两种主要的方法可以将事件插入到人们的日历中:

  1. 您可以将他们作为与会者添加到您的活动中,然后活动将向他们发送电子邮件并将其添加到他们的日历中
  2. 如果您都在同一个域中,并且正在为该域编写应用程序,则可以创建一个服务帐户(https://developers.google.com/accounts/docs/OAuth2ServiceAccount)然后使用域范围的授权:https://developers.google.com/drive/web/delegation(是的,链接是针对驱动器API的,但验证在驱动器和日历之间都是一样的,所以只需将驱动器位替换为日历即可)