Google Calendar API活动邀请未使用服务帐户身份验证发送到非Gmail帐户

时间:2017-09-01 08:05:52

标签: php google-calendar-api

我正在使用谷歌服务帐户将谷歌日历api实现到我的网络应用程序。

据我研究了很多文件但没有找到确切的解决方案。

我尝试了以下事项:

1)使用" OAuth 2.0客户端ID "证书。     - 我可以在谷歌日历中创建活动。     - 还向所有与会者发送电子邮件通知(包括非gmail帐户)。     - 但缺点是它必须要求谷歌身份验证(谷歌登录)。     - 根据我的要求,任何人都可以在没有谷歌登录的情况下在谷歌日历活动中创建。

2)使用" 服务帐户"证书。     - 我可以在谷歌日历中创建活动。     - 仅在与会者之间向gmail地址发送电子邮件通知。     - 无需谷歌登录。

我更喜欢第二种方式。

$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等等)

请建议有什么方法可以解决这个问题。

由于

1 个答案:

答案 0 :(得分:0)

我发现问题出在唯一的“yopmail.com”域。对于其他电子邮件域,它工作正常。谷歌活动邀请正在制定谷歌通知标准和规范。