php - No events being shown when retrieving events using google calendar -
i encountering problem code when trying retrieve events on google calendar. below code:
<?php 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 generate // client id, client secret, , register redirect uri. $client->setclientid('client id'); $client->setclientsecret('client secret'); $client->setredirecturi('redirect uri'); $client->setdeveloperkey('developer key'); $cal = new google_calendarservice($client); $events = $cal->events->listevents('email address google calendar'); echo $events; ?>
when print out events of google calendar, empty array. sure have several events in google calendar.
in fact, event tried add event using code below:
$event = new google_event(); $event->setsummary('appointment'); $event->setlocation('somewhere'); $start = new google_eventdatetime(); $start->setdatetime('2013-08-23t10:00:00.000-07:00'); $event->setstart($start); $end = new google_eventdatetime(); $end->setdatetime('2013-08-23t10:25:00.000-07:00'); $event->setend($end); echo $events; $createdevent = $cal->events->insert('email address google calendar', $event);
however, when code end receiving error says:
fatal error: uncaught exception 'google_serviceexception' message 'error calling post https://www.googleapis.com/calendar/v3/calendars/'email address google calendar'/events?key='key'......................................lib/google-api-php-client/src/io/google_rest.php on line 66
can me on this?
as it's array need use print_r instead of echo. try replacing:
echo $events;
with
print"<pre>".print_r($events, true)."</pre>";
Comments
Post a Comment