【发布时间】:2014-03-25 00:17:42
【问题描述】:
所以我花了几个小时试图弄清楚如何让谷歌日历工作。 V3 没有日历示例,我想我找到了一个带有 simple.php 示例的旧 git。我输入了我的客户端 ID、秘密、重定向和 api 密钥。
然后我浏览 simple.php 页面,它请求授权,重定向回来并显示日历列表,它只是一堆与我的日历完全无关的随机内容的数组。
如何让它显示在实际日历中?为什么没有这方面的任何文档?
我只是想让谷歌日历显示在登录用户的网页上。认为会有很多这样的文档。这不能使用google 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:\xampp\htdocs\wordpress\wp-content\themes\twentyfourteen\google-api-php-client\examples\calendar\simple.php on line 33
Notice: Trying to get property of non-object in C:\xampp\htdocs\wordpress\wp-content\themes\twentyfourteen\google-api-php-client\examples\calendar\simple.php on line 33
Fatal error: Call to a member function get() on a non-object in C:\xampp\htdocs\wordpress\wp-content\themes\twentyfourteen\google-api-php-client\examples\calendar\simple.php on line 33
【问题讨论】:
-
不知道为什么有人会觉得有必要投反对票。做一些研究我不是唯一一个在寻找文档的人。
-
这里是google calendar api的文档,包括代码示例、how tos和api参考developers.google.com/google-apps/calendar
-
为了澄清您的问题,您是否尝试将谷歌日历嵌入到另一个网页中?如果是这样,也许这会有所帮助support.google.com/calendar/answer/41207
-
是的,但这只会显示一个我想让它可以编辑的日历,就像我在谷歌上查看日历一样。这似乎是不可能的。客户端库如何操作也是一个笑话。 V3 中没有关于日历的操作方法,它提到来堆栈以获得支持,哈哈。还有很多路径和其他示例已经过时了。
-
显然,如果没有正确的权限,您将无法编辑日历。不过,您可以使用日历 API 来更改 ACL。
标签: php google-api google-calendar-api google-api-client