类需要哪个PHP脚本文件

类需要哪个PHP脚本文件

本文介绍了Google Calendar PHP API v3中的ical()类需要哪个PHP脚本文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在构建的PHP脚本中出现错误:

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

致命错误:在第74行的/home/abc/public_html/app/mods/googleCalendar_3.0/cache_events.php中找不到类"ical"

这是我的脚本文件中的摘录:

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

注意:

日历是公开可见的

为了确保,我添加了我的Auth&为了安全起见,API的>凭据>服务帐户>电子邮件地址

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

推荐答案

如果您要使用服务帐户,则您的代码可能已关闭很多.我无法测试此代码,我的本地网络服务器正在运行,但是应该关闭了,您可能不得不猜测$service->Events->list();部分,这只是一种猜测.确保您在相关日历上已将用户的服务帐户电子邮件地址添加为用户,并且该地址应该可以使用.

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);

注意:您所需要的只是Google Dir,您可以删除不需要的所有内容.代码是从我仅有的教程中编辑的,该教程在 PHP 中显示了此内容.

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.

这篇关于Google Calendar PHP API v3中的ical()类需要哪个PHP脚本文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-03 19:18