how to create an event on google calendar using php

后端 未结 3 700
温柔的废话
温柔的废话 2021-02-11 05:44

am trying to sync. events from my website to google *calendar* after

user give me a permission to write on calendar .

3条回答
  •  别跟我提以往
    2021-02-11 06:15

    Have you tried to read the reference?

    Using quickAdd (which creates an event based on a simple string)

    https://developers.google.com/google-apps/calendar/v3/reference/events/quickAdd

    require_once 'google-api-php-client/src/Google_Client.php';
    require_once 'google-api-php-client/src/contrib/Google_CalendarService.php';
    
    $createdEvent = $service->events->quickAdd(
        'primary',
        'Appointment at Somewhere on June 3rd 10am-10:25am');
    
    echo $createdEvent->getId();
    

    Or using insert

    https://developers.google.com/google-apps/calendar/v3/reference/events/insert

    require_once 'google-api-php-client/src/Google_Client.php';
    require_once 'google-api-php-client/src/contrib/Google_CalendarService.php';
    
    $event = new Google_Event();
    $event->setSummary('Appointment');
    $event->setLocation('Somewhere');
    $start = new EventDateTime();
    $start->setDateTime('2011-06-03T10:00:00.000-07:00');
    $event->setStart($start);
    $end = new EventDateTime();
    $end->setDateTime('2011-06-03T10:25:00.000-07:00');
    $event->setEnd($end);
    $attendee1 = new EventAttendee();
    $attendee1->setEmail('attendeeEmail');
    // ...
    $attendees = array($attendee1,
                       // ...
                      );
    $event->attendees = $attendees;
    $createdEvent = $service->events->insert('primary', $event);
    
    echo $createdEvent->getId();
    

提交回复
热议问题