这甚至适用于v3吗?没有文档

时间:2014-03-25 00:17:42

标签: php google-api google-calendar-api google-api-client

所以我花了几个小时试图找出如何让谷歌日历工作。 V3没有日历示例,我想我找到了一个较旧的git,它有simple.php示例。我输入了我的客户端ID,密码,重定向和api密钥。

然后我浏览了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:\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

1 个答案:

答案 0 :(得分:0)

我猜你接下来要做的就是列出这个日历中的事件。 https://developers.google.com/google-apps/calendar/v3/reference/events/list

您可以选择要对引用中的日历或事件做什么,然后您可以在每个页面的末尾找到php示例。

相关问题