基本概要:我编写了一个客户端日历,允许人们安排约会并保留时间段(例如,预订记录在数据库中,第二个人不能选择相同的时间段)以便于联合和打印这些在提供商方面的约会,他们要求我将这些事件推送到一个谷歌日历。我已经为它创建了一个谷歌帐户和一个日历,然后创建了 API 密钥,可以在同一个谷歌用户下访问日历 API。所以我希望我的网站每次都使用这个用户的凭据来创建事件。看起来这将是一个“服务帐户”,但它似乎无权访问用户数据,甚至没有创建应用程序的用户。
关于如何解决这个问题的任何想法?如果看起来它应该非常简单,而且我不可能是第一个想要做这样的事情的人,但如果我能找到任何例子,我该死的。
这是代码片段
$event = new Google_Event();
$event->setSummary($title);
$event->setLocation($location);
$start = new Google_EventDateTime();
$start->setDateTime($date . 'T' . $startTime . ':00.000-06:00');
$event->setStart($start);
$end = new Google_EventDateTime();
$end->setDateTime($date . 'T' . $endTime . ':00.000-06:00');
$event->setEnd($end);
$attendee1 = new Google_EventAttendee();
$attendee1->setEmail($email);
$attendees = array($attendee1);
$event->attendees = $attendees;
$client = new Google_Client();
$service = new Google_CalendarService($client);
$createdEvent = $service->events->insert('my calendar ID', $event);
和错误
Uncaught exception 'Google_ServiceException' with message 'Error calling POST https://www.googleapis.com/calendar/v3/calendars/projecthimcal@gmail.com/events?key=AIzaSyAfSCfLJCMSkGRmjZXRtChPPcMNmEuCZow: (401) Login Required' in /home/mydomain.com/wp-content/themes/mytheme/libs/gAPI/io/Google_REST.php:66