Ram*_*amz 7 android calendar google-calendar-api google-api
嗨,我正在尝试使用Android中的Google日历API在Google日历中创建一个事件.
我创建了一个由Google提供的示例项目 ,我按照每个步骤成功编译了项目.
但在这个Google日历示例中,我只能为我的Google日历帐户创建日历名称,我无法创建任何活动.
有没有办法在Google日历中创建活动?如果是这样我该怎么办?
小智 6
这真是一个巨大的痛苦 - 但我终于让它至少可以用于创建事件了。
下载最新的 Google PHP API zip,并将其上传到网络服务器上的包含文件夹中。使用 Google API Console 设置 API 客户端。确保将重定向 url 设置为与页面的 url 相同 - 这样它就会重定向到其自身。
我最初只是为事件详细信息设置了一些变量,如果需要,您可以制作一个将这些变量推入的表单。
这是我的代码:
<?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>";
}
?>
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
28785 次 |
最近记录: |