2014-11-21 125 views
1

我正尝试使用Google Calendar API创建活动并邀请多个与会者。Google Calendar API - sendNotifications不起作用

foreach($email_invite_arr as $item){ 
    if($item){ 
     $attendee = new Google_Service_Calendar_EventAttendee(); 
     $attendee->setEmail($item); 
     $attendee_arr[]= $attendee; 
    } 
} 
$event->setAttendees($attendee_arr); 

$optParams = Array(
    'sendNotifications' => true, 
    'maxAttendees' => 10 
); 
$createdEvent = $service->events->insert('primary', $event, $optParams); 

一切工作正常。该活动正在与所有与会者一起创建。但电子邮件通知没有发送。我在这里做错了什么?

+0

电子邮件通知不发送过去创建的事件。此外,请检查alertsOnRespondedEventsOnly它是否设置为true或false(针对您尝试插入事件的日历)。如果这是“真”,那么事件提醒将仅发送给用户的回复状态为“是”或“可能”的事件。 – SGC 2014-11-21 18:54:21

回答

-1

因此,在Calendar API的insert方法中似乎存在问题。我遵循这里建议的决议:https://code.google.com/p/google-apps-script-issues/issues/detail?id=574,它的工作。以下是我的修改代码:

foreach($email_invite_arr as $item){ 
    if($item){ 
     $attendee = new Google_Service_Calendar_EventAttendee(); 
     $attendee->setEmail($item); 
     $attendee_arr[]= $attendee; 
    } 
} 

$optParams = Array(
    'sendNotifications' => true, 
); 
$createdEvent = $service->events->insert('primary', $event); 

$event->setAttendees($attendee_arr); 
$service->events->patch('primary',$createdEvent->getId(),$event, $optParams); 

这里的关键是patch方法。

+0

sendNotifications也适用于插入。我不认为你的答案是其他人应该学习的东西。这已经在http://stackoverflow.com/questions/19158964/google-calendar-api-invitation-email-doesnt-send-to-attendees-when-create-even – luc 2014-11-25 02:41:31

+0

@luc回答..你有工作吗例如证明插入方法有效吗?我最初只使用'insert'方法(如我的问题所述)使用Google Calendar API的最新代码。它没有工作。我的答案指出了该代码中的缺陷,并提供了一个解决该问题的临时解决方案。让我知道.. – soundswaste 2014-11-27 08:57:32

0

通知是由与会者的日历设置的。活动组织者只能为他们自己的日历设置通知,而不能为与会者。考虑通过蜗牛邮件发送正式聚会邀请函,在派对开始前20分钟提醒人们离开房屋肯定不是主持人的工作!

与会者通知将根据与会者的日历默认通知进行设置,除非与会者设置了自定义通知。

如果您确实想为与会者设置通知,则需要对每位与会者进行身份验证。

+0

Jay,通知也不会发送给与会者。 – soundswaste 2014-11-24 06:38:27

+1

我认为你很混淆通知和提醒。 – djsmith 2014-12-01 18:31:50

1

您不需要修补程序功能。 sendNotification在创建事件时工作得很好。

我发现的是,目前的指南并不适合我在循环参与者。以下是我的工作:

foreach ($staffUserArr as $staffEmail) 
{ 
    $attendee1 = new Google_Service_Calendar_EventAttendee(); 
    $attendee1->setEmail($staffEmail); 

    $attendees[] = $attendee1; 
} 

$newEvent->attendees = $attendees; 

$optParams = Array(
     'sendNotifications' => true, 
); 

$service->events->insert('primary',$newEvent,$optParams);