Google Calendar API - sendNotifications is not working

不想你离开。 提交于 2019-12-24 10:49:02

问题


I am trying to use Google Calendar API to create event and invite multiple attendees.

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);

Everything works fine. The event is getting created with all attendees. But Email notifications are not getting sent. What am I doing wrong here?


回答1:


You don't need the patch function. The sendNotification works just fine with creating the event.

What I found was that the current guide didn't work for me to cycle through attendees. Here's what worked for me:

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);



回答2:


Notifications are set by the attendee's calendar. The event organizer can only set notifications for their own calendar not for attendees. Think about it in terms of sending a formal party invitation via snail mail, it's certainly not the host's job to remind people to leave the house 20 minutes before the party starts!

The attendee notifications will be set based on the attendee's default notifications for the calendar unless the attendee sets custom notifications.

If you really want to set the notifications for the attendee, you'll need to be authenticated as each attendee.




回答3:


So there seems to be a problem with insert method of Calendar API. I followed the resolution suggested here : https://code.google.com/p/google-apps-script-issues/issues/detail?id=574 and it worked. Following is my modified code :

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 );

The key here is the patch method.



来源:https://stackoverflow.com/questions/27058451/google-calendar-api-sendnotifications-is-not-working

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!