我正在使用Google服务帐户将Google Calendar API实现到我的Web应用程序。
据我研究了很多文档,但找不到精确的解决方案。
我尝试了以下内容:
1)使用" OAUTH 2.0客户端ID "凭据。 - 我可以在Google日历中创建事件。 - 还发送电子邮件发送给所有与会者(包括非Gmail帐户)的电子邮件通知。 - 但是缺点是必须需要Google身份验证(Google登录)。 - 根据我的要求,任何人都可以在Google日历事件中创建而无需Google登录。
2)使用" 服务帐户"凭据。 - 我可以在Google日历中创建事件。 - 仅在与会者中将电子邮件通知发送到Gmail地址。 - 不需要Google登录。
我更喜欢第二种方式。
$rule = new Google_Service_Calendar_AclRule();
$scope = new Google_Service_Calendar_AclRuleScope();
$scope->setType("user");
$scope->setValue("xxx@gmail.com");
$scope->setValue("xxxxxxx@xxx.iam.gserviceaccount.com");
$rule->setScope($scope);
$rule->setRole("owner");
$client = new Google_Client();
$client->setApplicationName("Calendar Service");
$client->setAuthConfig('service_secrets.json');
$client->addScope(Google_Service_Calendar::CALENDAR);
$calendar_service = new Google_Service_Calendar($client);
$calendarList = $calendar_service->calendarList;
$event_data = new Google_Service_Calendar_Event(array(
'summary' => "Service Account Test Event",
'location' => 'Los Angeles',
'description' => 'This is extrieme test event',
'start' => array(
'dateTime' => '2017-09-13T09:00:00-07:00',
'timeZone' => 'America/Los_Angeles',
),
'end' => array(
'dateTime' => '2017-09-13T17:00:00-07:00',
'timeZone' => 'America/Los_Angeles',
),
'recurrence' => array(
'RRULE:FREQ=DAILY;COUNT=2'
),
'attendees' => array(
array('email' => 'xxx@yopmail.com'),
array('email' => 'xxx@gmail.com'),
array('email' => 'xxx@hotmail.com'),
),
'reminders' => array(
'useDefault' => FALSE,
'overrides' => array(
array('method' => 'email', 'minutes' => 24 * 60),
array('method' => 'popup', 'minutes' => 10),
),
)
));
$calendarId = 'dsfsdfasdfxxxxxxxxxxxxxx@group.calendar.google.com';
$sendNotifications = array('sendNotifications' => true);
$event_response = $calendar_service->events->insert($calendarId, $event_data, $sendNotifications);
我唯一的问题是我无法将事件通知发送到非Gmail帐户,这意味着(hotmail.com,yopmail.com等
请建议有任何解决此问题的方法。
谢谢
我发现问题在于唯一的" yopmail.com" 域。对于其他电子邮件域,它可以正常工作。Google活动邀请正在遵循Google通知标准和规范。