Google Calendar API

olejan1991

Новичок
Выдает вот такую ошибку при попытке редактирования события:
Catchable fatal error: Argument 3 passed to Google_EventsServiceResource::update() must be an instance of Google_Event, array given, called in /home/u730711811/public_html/calendar/editEvent.php on line 47 and defined in /home/u730711811/public_html/google-api-php-client/src/contrib/Google_CalendarService.php on line 613

Вот код
PHP:
<?php
//echo $_POST['editEventInfo'];


require_once '../google-api-php-client/src/Google_Client.php';
require_once '../google-api-php-client/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('**********-***************.apps.googleusercontent.com');
$client->setClientSecret('********************************');
$client->setRedirectUri('http://kot.******.com/index.php');
$client->setDeveloperKey('****************');
$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()) {
    //echo $_POST['editEventInfo'];
    $eventInfo = explode(';', $_POST['editEventInfo']);
    /*echo '<pre>';
    print_r($eventInfo);
    echo '</pre>';*/
    //$optParams = 'maxAttendees' => 'FALSE';
    $event = $cal->events->get($eventInfo[1], $eventInfo[0]);
    //echo gettype($event);
  /* echo '<pre>';
    print_r($event);
    echo '</pre>';*/
    //$optParams = array('end.date'=>'2014-02-10');
// вот тут происходит та самая попытка обновления
    $cal->events->update($eventInfo[1], $eventInfo[0], $event /*array("end.dateTime" => "2014-03-20T01:00:00+02:00", "start.dateTime" => "2014-03-20T01:00:00+02:00")*/);
    //echo '<pre>';
    //print_r($eventInfo);
    //echo '</pre>';
    $_SESSION['token'] = $client->getAccessToken();
} else {
    $authUrl = $client->createAuthUrl();
    print "<a class='login' href='$authUrl'>Войти в Google Calendar</a>";
}
?>
В чем может быть причина?
 
Последнее редактирование модератором:

Вурдалак

Продвинутый новичок
Как следует из ошибки, в $event должен быть объект класса Google_Event, а не массив.
 

olejan1991

Новичок
я понимаю, но тут мы видим обращение к функции, которая должна возвращать объект класса Google_Event
PHP:
$event = $cal->events->get($eventInfo[1], $eventInfo[0]);
, но она возвращает массив. Вот та самая функция
PHP:
 public function get($calendarId, $eventId, $optParams = array()) {
      $params = array('calendarId' => $calendarId, 'eventId' => $eventId);
      $params = array_merge($params, $optParams);
      $data = $this->__call('get', array($params));
      if ($this->useObjects()) {
        return new Google_Event($data);
      } else {
        return $data;
      }
    }
 
Сверху