PHP Google Calendar API: Adding Multiple Events at Once

旧巷老猫 提交于 2020-01-24 09:05:47

问题


Using version 3 of the Google Calendar API. I can add one event at a time, but I want to add multiple events at once. Any idea how to do this? I assign $authUrl to my template below, the user clicks a link that says "add all items to google calendar", authorizes that Google can access the account, it goes back to my callback URL with $_GET['code'] assigned so the whole $client->getAccessToken() block gets executed.

Obviously I'm using dummy data now, but I want to populate the fields with data from expression engine. I have that data available, but for the sake of simplicity for this question, spared the crap and put in test data.

This code works for one event:

$client = new apiClient();
$client->setApplicationName("Band Calendar");
$cal = new apiCalendarService($client);

if (isset($_GET['logout'])) {
    unset($_SESSION['token']);
}

if (isset($_GET['code'])) {
    $client->authenticate();
    $_SESSION['token'] = $client->getAccessToken();
    header('Location: http://' . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF']);
}

if (isset($_SESSION['token'])) {
    $client->setAccessToken($_SESSION['token']);
}

$authUrl = $client->createAuthUrl();

if ($client->getAccessToken()) {

$event = new Event();
$event->setSummary("test title");
$event->setLocation("test location");
$start = new EventDateTime();
$start->setDateTime('2012-03-03T09:25:00.000-05:00');
$event->setStart($start);
$end = new EventDateTime();
$end->setDateTime('2012-03-03T10:25:00.000-05:00');
$event->setEnd($end);
$attendee1 = new EventAttendee();
$attendee1->setEmail('email@email.com');
$attendees = array($attendee1);
$event->attendees = $attendees;
$createdEvent = $cal->events->insert('primary', $event);

echo $createdEvent->getId();

$_SESSION['token'] = $client->getAccessToken();
}

I've noticed that there's a "class Events" that I can instantiate (rather than just instantiating a single Event object) and that it has an $items member variable. I'm guessing I can add a bunch of Event objects to the $item member variable and then send a bunch of events at once, but can't seem to get it right. Anyone have experience with this?


回答1:


Judging from the PHP and Java documentation for v3 this is not possible. Calendar.Events (in Java) is a wrapper around a calendar's event-related methods in the API: you can ask it to insert one event, but you cannot use it as a representation of several events and e.g. pass it to the server (for bulk insert).

At least that's what I've concluded for now. (I could also use the feature.)



来源:https://stackoverflow.com/questions/9439104/php-google-calendar-api-adding-multiple-events-at-once

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