0

I want to add a Calendar on Google Calendar with this code.

function addCalendar($client, $nomeInsegnamento, $codiceInsegnamento){
    $calendar = new Calendar();
    $calendar->setSummary($nomeInsegnamento." - ".$codiceInsegnamento);
    $calendar->setTimeZone('Europe/Rome');
    return $client -> calendars -> insert($calendar);
}

i have imported the Google API library for PHP

require_once '../src/Google_Client.php';
require_once '../src/contrib/Google_CalendarService.php';

but it always get this error

Fatal error: Class 'Calendar' not found in D:\Programmi\EasyPHP-DevServer-13.1VC9\data\localweb\projects\GCE\prova.php on line 182
Kara
  • 6,115
  • 16
  • 50
  • 57
marzobryant90
  • 33
  • 1
  • 9

1 Answers1

0

There is no such class Calendar in Google_CalendarService.php: https://code.google.com/p/google-api-php-client/source/browse/trunk/src/contrib/Google_CalendarService.php

You'd probably want to checkout this answer

Community
  • 1
  • 1
Nir Alfasi
  • 53,191
  • 11
  • 86
  • 129
  • Ok, i see that the documentation is very incomplete. Now what class i have to import? `$client = new Google_Client(array('use_objects' => true)); $cal = new Google_CalendarService($client); function addCalendar($cal, $nomeInsegnamento, $codiceInsegnamento){ $calendar = new Calendar(); $calendar->setSummary($nomeInsegnamento." - ".$codiceInsegnamento); $calendar->setTimeZone('Europe/Rome'); return $cal -> calendars -> insert($calendar); }` – marzobryant90 Jun 08 '13 at 07:53
  • The same class: `Google_CalendarService.php` – Nir Alfasi Jun 08 '13 at 07:56
  • Because i got the same error also with `$client = new Google_Client(array('use_objects' => true));` – marzobryant90 Jun 08 '13 at 07:56
  • So `Google_Client.php` is not included correctly (probably wrong path or something - check out the warnings) – Nir Alfasi Jun 08 '13 at 08:00
  • No it's in the correctly position `require_once '../src/Google_Client.php'; require_once '../src/contrib/Google_CalendarService.php';` the connection with Oauth 2.0 work fine, i don't know because it doesn't found the library correctly do you want to see all the code? – marzobryant90 Jun 08 '13 at 08:04
  • Ok i have correct the code, but now i have the problem with the insert() function, i write this `function addCalendar($cal, $nomeInsegnamento, $codiceInsegnamento){ $calendar = new Google_Calendar(); $calendar -> setSummary($nomeInsegnamento." - ".$codiceInsegnamento); $calendar -> setTimeZone('Europe/Rome'); $c = $cal -> calendars -> insert($calendar); echo $c -> getSummary; }` why don't work??? the 2nd parameter in Google_CalendarService is optional – marzobryant90 Jun 08 '13 at 08:23
  • the problem is that $cal hasn't instanciate, i pass it like a parameter to the function but there is something wrong.. thanks for your help – marzobryant90 Jun 08 '13 at 08:38
  • @marzobryant90 that's 3 questions you already asked in one post (I answered two of them). Posting code in comments is not readable as well as misleading (the title and the original post are not relevant anymore), if this question has been answered - accept the answer, move on and post a new question, thanks. – Nir Alfasi Jun 10 '13 at 19:22