所以我已经花了几个小时试图弄清楚如何让谷歌日历工作。V3没有日历示例,我猜我找到了一个旧的git,它有简单的。php示例。我输入了我的客户端id, secret, redirect和api key。
我然后浏览simple.php页面,它请求授权,重定向回来,并显示日历列表,这只是一堆随机的东西与我的日历无关的数组。
我如何让这个显示在实际的日历中?为什么没有这方面的文件?
我只是想让谷歌日历显示在一个网页上的用户谁是登录。我想应该有很多这样的文档。这是不可能使用谷歌api?
<?php
require_once '../../src/Google_Client.php';
require_once '../../src/contrib/Google_CalendarService.php';
session_start();
$client = new Google_Client();
$client->setApplicationName("Google Calendar PHP Starter Application");
// Visit https://code.google.com/apis/console?api=calendar to generate your
// client id, client secret, and to register your redirect uri.
$client->setClientId('myClientId');
$client->setClientSecret('myClientSecret');
$client->setRedirectUri('http://localhost/wordpress/wp-content/themes/twentyfourteen/google-api-php-client/examples/calendar/simple.php');
$client->setDeveloperKey('myApiKey');
$cal = new Google_CalendarService($client);
if (isset($_GET['logout'])) {
unset($_SESSION['token']);
}
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()) {
$calList = $cal->calendarList->listCalendarList();
print "<h1>Calendar List</h1><pre>" . print_r($calList, true) . "</pre>";
$calendar = $service->calendars->get('primary');
echo $calendar->getSummary();
$_SESSION['token'] = $client->getAccessToken();
} else {
$authUrl = $client->createAuthUrl();
print "<a class='login' href='$authUrl'>Connect Me!</a>";
}
这让我
Calendar List
Array
(
[kind] => calendar#calendarList
[etag] => "uz4dSMPAwpogj1sIr_PP7Gm-AxY/Dkoq7AkW5RQPry2qgnRZSo6dywQ"
[items] => Array
(
[0] => Array
(
[kind] => calendar#calendarListEntry
[etag] => "uz4dSMPAwpogj1sIr_PP7Gm-AxY/OfDIPQtOizBQ0xUM55cH-RiMGw4"
[id] => myEmailAddress
[summary] => myEmailAddress
[timeZone] => America/Los_Angeles
[colorId] => 15
[backgroundColor] => #9fc6e7
[foregroundColor] => #000000
[selected] => 1
[accessRole] => owner
[defaultReminders] => Array
(
[0] => Array
(
[method] => email
[minutes] => 10
)
[1] => Array
(
[method] => popup
[minutes] => 30
)
)
[notificationSettings] => Array
(
[notifications] => Array
(
[0] => Array
(
[type] => eventCreation
[method] => email
)
[1] => Array
(
[type] => eventChange
[method] => email
)
[2] => Array
(
[type] => eventCancellation
[method] => email
)
[3] => Array
(
[type] => eventResponse
[method] => email
)
)
)
[primary] => 1
)
[1] => Array
(
[kind] => calendar#calendarListEntry
[etag] => "uz4dSMPAwpogj1sIr_PP7Gm-AxY/sjFVOlVft6ECLQqbceDo4SWExfc"
[id] => #contacts@group.v.calendar.google.com
[summary] => Contacts' birthdays and events
[description] => Your contacts' birthdays and anniversaries
[timeZone] => America/Los_Angeles
[colorId] => 17
[backgroundColor] => #9a9cff
[foregroundColor] => #000000
[selected] => 1
[accessRole] => reader
)
[2] => Array
(
[kind] => calendar#calendarListEntry
[etag] => "uz4dSMPAwpogj1sIr_PP7Gm-AxY/R5Pe_cDz8Mqz0fmwnfeci-di2wo"
[id] => en.usa#holiday@group.v.calendar.google.com
[summary] => Holidays in United States
[description] => Holidays in United States
[timeZone] => America/Los_Angeles
[colorId] => 9
[backgroundColor] => #7bd148
[foregroundColor] => #000000
[selected] => 1
[accessRole] => reader
)
)
)
Notice: Undefined variable: service in C:xampphtdocswordpresswp-contentthemestwentyfourteengoogle-api-php-clientexamplescalendarsimple.php on line 33
Notice: Trying to get property of non-object in C:xampphtdocswordpresswp-contentthemestwentyfourteengoogle-api-php-clientexamplescalendarsimple.php on line 33
Fatal error: Call to a member function get() on a non-object in C:xampphtdocswordpresswp-contentthemestwentyfourteengoogle-api-php-clientexamplescalendarsimple.php on line 33
我猜你接下来要做的是列出这个日历中的事件。https://developers.google.com/google-apps/calendar/v3/reference/events/list
你可以在参考中选择你想要做的日历或事件,然后你可以在每页的末尾找到php示例。