Google Calendar API with PHP – Service Account -
i've been trying several days google calendar api , running absolutely no luck. i'm using php , service account authentication. have followed tutorial (http://www.daimto.com/google-calendar-api-with-php-service-account/) , code below tutorial.
i have setup developers console allow calendar api, , have added developers email address calendar share section.
when run code, blank page - no error, no text of kind, blank white page. i'm lost - appreciated. cheers
<?php require 'vendor/autoload.php'; session_start(); $client_id = '123456789-qwertyuiop.apps.googleusercontent.com'; $email_address = '123456789-qwertyuiop@developer.gserviceaccount.com'; $key_file_location = 'path_to_key/key.p12'; $client = new google_client(); $client->setapplicationname("client_library_examples"); $key = file_get_contents($key_file_location); // separate additional scopes comma $scopes ="https://www.googleapis.com/auth/calendar.readonly"; $cred = new google_auth_assertioncredentials( $email_address, array($scopes), $key ); $client->setassertioncredentials($cred); if($client->getauth()->isaccesstokenexpired()) { $client->getauth()->refreshtokenwithassertion($cred); } $service = new google_service_calendar($client); ?> <html><body> <?php $calendarlist = $service->calendarlist->listcalendarlist(); while(true) { foreach ($calendarlist->getitems() $calendarlistentry) { echo $calendarlistentry->getsummary()."<br>\n"; // events $events = $service->events->listevents($calendarlistentry->id); foreach ($events->getitems() $event) { echo "-----".$event->getsummary()."<br>"; } } $pagetoken = $calendarlist->getnextpagetoken(); if ($pagetoken) { $optparams = array('pagetoken' => $pagetoken); $calendarlist = $service->calendarlist->listcalendarlist($optparams); } else { break; } } ?>
when run code, blank page - no error, no text of kind, blank white page. i'm lost - appreciated. cheers
on note, running similar frustration , discovered script automatically created error_log in separate file on server. open in code editor , can see detailed responses. not sure if @ all, helped me ton.
Comments
Post a Comment