API Google日历,未创建环聊

时间:2015-05-21 11:11:06

标签: php symfony google-api google-calendar-api google-apps

我们有一个PHP应用程序,当我们使用de API在Google日历中创建活动时,此事件是在没有环聊链接的情况下生成的,但如果我们手动创建活动,则会使用环聊链接创建活动。选中在创建事件时自动创建环聊的选项。

代码是:

    $event = new Google_Service_Calendar_Event();
    $event->setSummary($summary);
    $event->setLocation('hangout');
    $start = new Google_Service_Calendar_EventDateTime();
    $start->setDateTime($startDate->format(\DateTime::ISO8601));
    $event->setStart($start);
    $end = new Google_Service_Calendar_EventDateTime();
    $end->setDateTime($endDate->format(\DateTime::ISO8601));
    $event->setEnd($end);


    $attendee1 = new Google_Service_Calendar_EventAttendee();
    $attendee1->setEmail($this->masterAccount);


    $attendees= [];
    $attendees[] = $attendee1;

    foreach($company->getUsers()->toArray() as $user){
        $attendee1 = new Google_Service_Calendar_EventAttendee();
        $attendee1->setEmail($user->getEmail());
        $attendees[] = $attendee1;
    }
    $event->attendees = $attendees;
    $createdEvent = $this->google_calendar_service->events->insert($company->getCalendar()->getCalendarId(), $event);

如果我们使用https://developers.google.com/google-apps/calendar/v3/reference/events/insert#try-it形式创建de Event,则会创建环聊链接而不会出现问题。

任何解决方案? 谢谢:))

2 个答案:

答案 0 :(得分:0)

我知道这个主题有点老,但是仍有许多人在努力使Calendar API正常工作。在访问了无数论坛之后,经过数小时的阅读文档并最终撞上墙,我终于想到了,关键要素是设置requestId

在我实现此功能时,该参数不是必需的,因此我跳过了它。

话虽如此,我的要求看起来像这样:

$event = new Google_Service_Calendar_Event(); //creating empty event
$event->setSummary("Staff meeting"); //title
$event->setLocation("Room 101"); //location
$event->setDescription("We will talk about salary raise!"); //description
$event->setColorId(9); //make it shine by setting color

$start = new Google_Service_Calendar_EventDateTime();
$start->setDateTime($startDate->format(DateTime::ISO8601));
$start->setTimeZone('Europe/Warsaw');
$event->setStart($start); //set start

$end = new Google_Service_Calendar_EventDateTime();
$end->setDateTime($endDate->format(DateTime::ISO8601));
$end->setTimeZone('Europe/Warsaw');
$event->setEnd($end); //set end

$event->setGuestsCanSeeOtherGuests(false); //I dont want others to see who's invited
$event->setGuestsCanModify(false); //I dont want others to modify event
$event->setGuestsCanInviteOthers(false); //I dont want others to invite
$event->setAnyoneCanAddSelf(false); //I allow only people invited by me, not some strangers walking by

//this part should be executed in loop, for every guest
$attendee = new Google_Service_Calendar_EventAttendee();
$attendee->setEmail("staffmeber1@mywebsite.com");
$attendee->setResponseStatus('accepted');
$attendees[] = $attendee;

//When the list is completed, set guests in event
$event->setAttendees($attendees);

//The most important part about creating hangout
$conferenceData = new Google_Service_Calendar_ConferenceData(); //defining we have conference
$req = new Google_Service_Calendar_CreateConferenceRequest(); //requesting google to create video meeting
$req->setRequestId("req_".time()); //some random string/number changed every call. according to docs subsequent calls with the same request id are ignored
$conferenceData->setCreateRequest($req); //set request for videoconference in conference data
$event->setConferenceData($conferenceData); //set conference data in out event

$creator = new Google_Service_Calendar_EventCreator();
$creator->setDisplayName("Big boss");
$creator->setEmail('boss@mywebsite.com');
$event->setCreator($creator);

$event->setStatus('confirmed'); //lets say everyone is attending :D


$result = $this->calendarClient->events->insert($this->calendarObject->getId(), $event, ['conferenceDataVersion' => 1, 'sendUpdates' => "none"]); //dont forget about conferenceDataVersion or every conference data will be ignored

答案 1 :(得分:-1)

在这里使用Python也会遇到问题,即无法使用环聊创建事件。似乎无法从程序更改设置,但是作为SGC pointed out,我只是从UI更改了Google日历设置,以在创建的每个事件上添加视频群聊。

enter image description here