简体   繁体   English

创建谷歌日历活动

[英]creating google calendar event

am trying to create google calendar event using the following code given below, but am getting class Event not found . 我正在尝试使用下面给出的以下代码创建谷歌日历事件,但我找不到类事件。 How to create a new event. 如何创建新事件。 please help 请帮忙

<?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");

         $client->setClientId('');
         $client->setClientSecret('');
         $client->setRedirectUri('simple.php');
         $client->setDeveloperKey('insert_your_developer_key');
         $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']);
        }

        $authUrl = $client->createAuthUrl();
if (!$client->getAccessToken()) {

here am creating the new event 这里正在创建新活动

          $event = new Event();
          $event->setSummary("test title");
          $event->setLocation("test location");
          $start = new EventDateTime();
          $start->setDateTime('04-03-2012 09:25:00:000 -05:00');
          $event->setStart($start);
          $end = new EventDateTime();
          $end->setDateTime('04-03-2012 10:25:00:000 -05:00');

          $createdEvent = $cal->events->insert('primary', $event);

          echo $createdEvent->getId();
}

I had the exact same problem. 我有同样的问题。 Their documentation very incomplete. 他们的文件很不完整。 The class names are wrong in their example. 类名在他们的例子中是错误的。 Here is the code I got to work: 这是我工作的代码:

$event = new Google_Event();
$event->setSummary('Halloween');
$event->setLocation('The Neighbourhood');
$start = new Google_EventDateTime();
$start->setDateTime('2012-10-31T10:00:00.000-05:00');
$event->setStart($start);
$end = new Google_EventDateTime();
$end->setDateTime('2012-10-31T10:25:00.000-05:00');
$event->setEnd($end);
$createdEvent = $cal->events->insert('[calendar id]', $event); //Returns array not an object

echo $createdEvent->id;

$cal->events->insert returns an array, not an object like in their example code. $cal->events->insert返回一个数组,而不是像示例代码中那样的对象。 If you want it to return an object you need to define it in your Google_Client call, like so: 如果您希望它返回一个对象,您需要在Google_Client调用中定义它,如下所示:

$client = new Google_Client(array('use_objects' => true));

I had this problem too, and it seems things have changed with Google's API again. 我也遇到了这个问题,似乎Google的API再次发生了变化。

Using the code example in the docs I was trying do 使用我尝试的文档中的代码示例

$calendar = new Calendar();

This threw an error for class Calendar not found. 这样就没有找到类Calendar的错误。 Turns out everything was renamed and I had to do the following: 事实证明所有内容都已重命名,我必须执行以下操作:

$calendar = new Google_Service_Calendar_Calendar();

Seems like an ok naming convention to avoid conflicts, but it would have been nice to update the docs. 看起来像一个确定的命名约定,以避免冲突,但更新文档本来不错。 So to solve OP's problem today he would now solve his issue using: 因此,为了解决OP今天的问题,他现在将使用以下方法解决他的问题:

$event = new Google_Service_Calendar_Event();

You can look through the file Google/Service/Calendar.php and you should see all the relevant classes named with this naming convention. 您可以查看文件Google / Service / Calendar.php,您应该看到使用此命名约定命名的所有相关类。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM