PHP Google Calendar API:一次添加多个事件 [英] PHP Google Calendar API: Adding Multiple Events at Once

查看:91
本文介绍了PHP Google Calendar API:一次添加多个事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用Google日历API的第3版.我可以一次添加一个事件,但是我想一次添加多个事件.任何想法如何做到这一点?我将$ authUrl分配给下面的模板,用户单击一个链接将所有项目添加到Google日历",授权Google可以访问该帐户,并返回到我的回调URL,并分配了$ _GET ['code'],整个$ client-> getAccessToken()块都将执行.

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

我注意到有一个我可以实例化的类事件"(而不只是实例化一个Event对象),并且它有一个$ items成员变量.我猜我可以将一堆Event对象添加到$ item成员变量中,然后立即发送一堆事件,但似乎做对了.任何人都有经验吗?

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?

推荐答案

Java v3的文档是不可能的.

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

这篇关于PHP Google Calendar API:一次添加多个事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆