[英]How to add event on google calendar using calendar API using android?
Hi I am trying to create an event in Google calendar using Google calendar API in android. 嗨,我正在尝试使用Android中的Google日历API在Google日历中创建一个事件。
I have created a sample project provided by Google , and I followed the each steps and compiled the project successfully. 我创建了一个由Google提供的示例项目,我按照每个步骤成功编译了项目。
But in this Example of Google calendar, I can only create a calendar name to my Google calendar account, I can't create any event. 但在这个Google日历示例中,我只能为我的Google日历帐户创建日历名称,我无法创建任何活动。
Is there any way to create an event in Google calendar? 有没有办法在Google日历中创建活动? If so how can I do it?
如果是这样我该怎么办?
This is such a giant pain in the ass - but I finally got it working for creating events at least. 这是一个巨大的痛苦 - 但我终于让它至少为创造事件而努力。
Download the most recent Google PHP API zip, and upload it to your includes folder on your webserver. 下载最新的Google PHP API压缩文件,并将其上传到您的网络服务器上的包含文件夹。 Use Google API Console to set up an API client.
使用Google API控制台设置API客户端。 Make sure you set your redirect url to be the same as your page's url - so it redirects to its self.
确保将重定向网址设置为与网页网址相同 - 因此重定向到自己的网址。
I've initially just set some variables for event details, you can make a form which shoves these in if you want. 我最初只为事件详细信息设置了一些变量,如果你愿意,你可以制作一个推送这些变量的表格。
Here's my code: 这是我的代码:
<?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('YOURCALENDARID@GOOGLE.COM', $event);
echo $createdEvent->id;
$_SESSION['token'] = $client->getAccessToken();
} else {
$authUrl = $client->createAuthUrl();
print "<a class='login' href='$authUrl'>Connect Me!</a>";
}
?>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.