2014-11-21 128 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);