如何使用android使用日历API在Google日历上添加事件?
问题描述:
嗨我想创建一个事件在谷歌日历在谷歌日历API在谷歌日历。如何使用android使用日历API在Google日历上添加事件?
我已经创建了一个由Google提供的示例项目,并且我遵循了每个步骤并成功编译了项目。
但是在这个Google日历的例子中,我只能为我的Google日历帐户创建一个日历名称,我不能创建任何事件。
有什么办法在Google日历中创建事件吗?如果是这样,我该怎么做?
答
这是一个巨大的痛苦在屁股 - 但我终于得到它的工作至少创造事件。
下载最新的Google PHP API zip,并将其上传到Web服务器上的includes文件夹。使用Google API Console设置API客户端。确保你将你的重定向网址设置为与你网页的网址相同 - 所以它重定向到它自己。
我最初只是为事件细节设置了一些变量,你可以制作一个表格,如果你想要的话就把它们推进去。
这里是我的代码:
<?php
$jobname = "BINGO";
$joblocation = "Your mums house";
$jobdescription = "An interview with a dog.";
$startofjob = "2013-12-20T17:00:00.000+00:00"; //datetimes must be in this format
$endofjob = "2013-12-20T18:00:00.000+00:00"; // YYYY-MM-DDTHH:MM:SS.MMM+HH:MM
//So that's year, month, day, the letter T, hours, minutes, seconds, miliseconds, + or -, timezoneoffset in hours and minutes
include('google-api-php-client/src/Google_Client.php');
include('google-api-php-client/src/contrib/Google_CalendarService.php');
session_start();
$client = new Google_Client();
$client->setApplicationName('doesntmatter-whateveryouwant');
$client->setClientId('yourclientid');
$client->setClientSecret('yourclientsecret');
$client->setRedirectUri('yourredirecturl-setingoogleconsole');
$client->setDeveloperKey('yourdeveloperkey');
$cal = new Google_CalendarService($client);
if (isset($_GET['code'])) {
$client->authenticate($_GET['code']);
$_SESSION['token'] = $client->getAccessToken();
header('Location: http://' . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF']);
}
if (isset($_SESSION['token'])) {
$client->setAccessToken($_SESSION['token']);
}
if ($client->getAccessToken()) {
$event = new Google_Event();
$event->setSummary($jobname);
$event->setDescription($jobdescription);
$event->setLocation($joblocation);
$start = new Google_EventDateTime();
$start->setDateTime($startofjob);
$event->setStart($start);
$end = new Google_EventDateTime();
$end->setDateTime($endofjob);
$event->setEnd($end);
$createdEvent = $cal->events->insert('[email protected]', $event);
echo $createdEvent->id;
$_SESSION['token'] = $client->getAccessToken();
} else {
$authUrl = $client->createAuthUrl();
print "<a class='login' href='$authUrl'>Connect Me!</a>";
}
?>
按照下面的链接。 https://stackoverflow.com/questions/43658751/add-events-to-calendar-programmatically?answertab=votes#tab-top –
请按照下面的链接。 https://stackoverflow.com/questions/43658751/add-events-to-calendar-programmatically?answertab=votes#tab-top –