Which PHP Script File is needed for ical() class in Google Calendar PHP API v3

半城伤御伤魂 提交于 2019-12-08 10:42:26

问题


I am getting an error in a PHP script I am building:

Fatal error: Class 'ical' not found in /home/abc/public_html/app/mods/googleCalendar_3.0/cache_events.php on line 74

Here is a snippet from my script file:

define('CLIENT_ID', 'ASDLJJLDSJLASDJLajdl;jdsljkASD;LKJASDLKJASD.apps.googleusercontent.com');

    require_once('autoload.php'); // 2014-11-24 part of /usr/local/lib/php/google-api-php-client
    require_once('/usr/local/lib/php/google-api-php-client/src/Google/Client.php'); // 2014-11-25
    require_once('/usr/local/lib/php/google-api-php-client/src/Google/Service/Calendar.php'); // 2014-11-25

    $ical = new ical('https://www.google.com/calendar/ical/CLIENT-ID/public/basic.ics');

    $eventListArray = array_filter($ical -> events(), "locationfilter");

    $eventCount = count($eventListArray);

    print_r($eventListArray); echo "<br>";
    echo "Event Count:" . $eventCount;echo "<br>";
    exit;

I am simply trying to retrieve all events in my public calendar

Notes:

Calendar is publicly viewable

Just to make sure, I added my Auth & API's > Credentials > Service Account > Email Address to it just to be safe


回答1:


If you want to use a service account your code is off quite a bit. I cant test this code my local webserver is acting up but it should be close you may have to tweek the $service->Events->list(); part it was kind of a guess. Make sure that you have the Service account email address added as a user on the calendar in question and it should work.

session_start();        
require_once 'Google/Client.php';
require_once 'Google/Service/Calendar.php';     
/************************************************   
 The following 3 values an befound in the setting   
 for the application you created on Google      
 Developers console.         Developers console.
 The Key file should be placed in a location     
 that is not accessable from the web. outside of 
 web root.       web root.

 In order to access your GA account you must    
 Add the Email address as a user at the     
 ACCOUNT Level in the GA admin.         
 ************************************************/
$client_id = '1046123799103-nk421gjc2v8mlr2qnmmqaak04ntb1dbp.apps.googleusercontent.com';
$Email_address = '1046123799103-nk421gjc2v8mlr2qnmmqaak04ntb1dbp@developer.gserviceaccount.com';     
$key_file_location = '629751513db09cd21a941399389f33e5abd633c9-privatekey.p12';     
$client = new Google_Client();      
$client->setApplicationName("Client_Library_Examples");
$key = file_get_contents($key_file_location);    
// seproate additional scopes with a comma   
$scopes ="https://www.googleapis.com/auth/calendar";    
$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);

// you should only need to do this once print this and you will
// find the calendarId for the one you are looking for.
$calendars = $service->calendarList->list();

$events = $service->events->list($yourCalendarID);

Note: all you need is the Google Dir you can remove everything above that you dont really need it. Code was edited from the only tutorial i have that shows this in PHP.



来源:https://stackoverflow.com/questions/27135093/which-php-script-file-is-needed-for-ical-class-in-google-calendar-php-api-v3

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!