在Calendar.php第32行

时间:2016-02-25 03:28:14

标签: php api calendar

我正在尝试创建一个简单的php表单,使用google-api-php将事件插入谷歌日历

但我总是遇到这个错误

致命错误:第32行的C:\ xampp \ htdocs \ gcalphp \ google-api-php-client \ src \ Google \ Service \ Calendar.php中找不到“Google_Service”类 < / p>

有人指向正确的方向吗?我一直在寻找解决方案。来自谷歌的文档不是任何帮助

这是片段

require_once "google-api-php-client/src/Google/Client.php";
require_once "google-api-php-client/src/Google/Service/Calendar.php";

$client = new Google_Client();
$client->setUseObjects(true);
$client->setApplicationName("your-app-name");
$client->setClientId("######1hg3nkk4cp28.apps.googleusercontent.com");
$client->setAssertionCredentials(
    new Google_AssertionCredentials(
        "######php@gcalproject-1230.iam.gserviceaccount.com",
        array(
            "https://www.googleapis.com/auth/calendar"
        ),
        file_get_contents("certificates/gcalproject-2cb78099d23a.p12")
    )
);

$service = new Google_CalendarService($client);

$event = new Google_Event();
$event->setSummary('Event 1');
$event->setLocation('Somewhere');
$start = new Google_EventDateTime();
$start->setDateTime('2016-02-22T19:00:00.000+01:00');
$start->setTimeZone('Europe/London');
$event->setStart($start);
$end = new Google_EventDateTime();
$end->setDateTime('2016-02-22T19:25:00.000+01:00');
$end->setTimeZone('Europe/London');
$event->setEnd($end);

$calendar_id = "#####bd@group.calendar.google.com";

$new_event = null;

try {
    $new_event = $service->events->insert($calendar_id, $event);
    //
    $new_event_id= $new_event->getId();
} catch (Google_ServiceException $e) {
    syslog(LOG_ERR, $e->getMessage());
}

$event = $service->events->get($calendar_id, $new_event->getId());
//
if ($event != null) {
    echo "Inserted:";
    echo "EventID=".$event->getId();
    echo "Summary=".$event->getSummary();
    echo "Status=".$event->getStatus();
}

1 个答案:

答案 0 :(得分:0)

我正在研究同样的问题。 发现您使用的是旧API语言,而不是新语言。 使用&#39; Google_Service_Calendar &#39;而不是&#39; Google_CalendarService &#39;

我仍在寻找 Google_EventDateTime &#39;的新命名。并会让你发布 w ^