2

I'm completely stuck and no where there seems to be a guide. I want to add multiple Google Calendar events at once thru Batch Request. But I don't know where to start. I've tried the code from Google Calendar API batch request PHP from this site, but I don't understand it.

I have a form where I can select a month, year and for every day of the month a work appointment.

The appointment is looked up in the database and returns start and end time. It's constructed in the Google DateTime.

if (isset($_POST['submit']))
{
    $year = $_POST['year'];
    $month =$_POST['month'];
    $day1 = $_POST['1'];
    $day2 = $_POST['2'];
    $day3 = $_POST['3'];

    if($day1 !="")
    {
      //... database lookup....
      addEvent($title,$desc,$locat,$from,$until,$calendar);
    }
    if($day2 !="")
    {
          //... database lookup....
          addEvent($title,$desc,$locat,$from,$until,$calendar);
    }
    if($day3 !="")
    {
          //... database lookup....
          addEvent($title,$desc,$locat,$from,$until,$calendar);
    }
    //... until day 31 ...

}

The event creation happens by function addEvent

function addEvent($title,$desc,$locat,$from,$until,$calendar)
{
    $event = new Google_Event();
    $event->setSummary($title);
    $event->setDescription($desc);
    $event->setLocation($locat);
    $start = new Google_EventDateTime();
    $start->setDateTime($from);
    $event->setStart($start);
    $end = new Google_EventDateTime();
    $end->setDateTime($until);
    $event->setEnd($end);
    $createdEvent = $service->events->insert( $calendar, $event);
}

To insert 1 event at a time is not a problem. But more than a few gives a white screen. How can I do a batch request to create up to 31 events? Any help is welcome.

Community
  • 1
  • 1
  • Have you tried anything ? Maybe generate a `csv` and then do the import of this ? – Pogrindis Apr 19 '16 at 14:17
  • alternatively, just iterate through your list of events to be added and add them as outlined in the documentation : https://developers.google.com/google-apps/calendar/v3/reference/events/import#examples – Pogrindis Apr 19 '16 at 14:22
  • I started to try with Batch Request but I don't know how that works or how to implement it –  Apr 19 '16 at 16:45

0 Answers0