Google Calendar API PHP fatal error -


i "connect me" link every time, after clicking , connecting, , refreshing browser. also, error,

as suggested in answer below, have made changes, , added them here. has created new error:

fatal error: uncaught exception 'google_serviceexception' message 'error calling https://www.googleapis.com/calendar/v3/users/me/calendarlist?key=aizasydxm2epulkfrogluo0dppebknimmvpfkxy: (401) login required' in ####.org/google-api-php-client/src/io/google_rest.php:66 stack trace: #0 ####.org/google-api-php-client/src/io/google_rest.php(36): google_rest::decodehttpresponse(object(google_httprequest)) #1 ####.org/google-api-php-client/src/service/google_serviceresource.php(177): google_rest::execute(object(google_httprequest)) #2 #####/google-api-php-client/src/contrib/google_calendarservice.php(154): google_serviceresource->__call('list', array) #3 ####/avl/index2.php(44): google_calendarlistserviceresource->listcalendarlist() #4 {main} thrown in /######.org/google-api-php-client/src/io/google_rest.php on line 66

<?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("#####");  // visit https://code.google.com/apis/console?api=calendar generate // client id, client secret, , register redirect uri. $client->setclientid('327425587799.apps.googleusercontent.com'); $client->setclientsecret('*******'); $client->setredirecturi('http://www.######.net/oauth2callback'); $client->setdeveloperkey('*******'); $client->setuseobjects(true);   $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()) { $callist = $cal->calendarlist->listcalendarlist(); print "<h1>calendar list</h1><pre>" . print_r($callist, true) . "</pre>";   $_session['token'] = $client->getaccesstoken(); } else { $authurl = $client->createauthurl(); print "<a class='login' href='$authurl'>connect me!</a>"; }   $calendarlist = $cal->calendarlist->listcalendarlist(); while(true){ foreach($calendarlist->getitems()as $calendarlistentry){   echo $calendarlistentry->getsummary(); } $pagetoken = $calendarlist->getnextpagetoken(); if($pagetoken){   $optparams = $cal->calendarlist->listcalendarlist($optparams); }else{   break; } } 

it appears using $service should have $cal.

so $calendarlist = $service->calendarlist->listcalendarlist(); should $calendarlist = $cal->calendarlist->listcalendarlist();

and $calendarlist = $service->calendarlist->listcalendarlist($optparams); should $calendarlist = $cal->calendarlist->listcalendarlist($optparams);


Comments

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -