Я пытаюсь использовать API Google через PHP для получения событий календаря.Моя среда
- Windows: 10
- PHP: 7.0
- Apache: 2.4
- Google API загружается с помощью команды: composer требуется google / apiclient:"^ 2.0"
Я использую следующее в качестве тестового кода (test2.php):
<html>
<head>
<title>PHP Test</title>
</head>
<body>
This is a line of text in test2.php
<?php
require_once 'C:\PHP\vendor\autoload.php';
$client = new Google_Client();
// $credentialsJson should contain the path to the json file downloaded from the API site
$credentialsJson = 'C:\Apache24\htdocs\credentials.json';
$credentials = $client->loadServiceAccountJson(
$credentialJson,
'https://www.googleapis.com/auth/calendar'
);
$client->setAssertionCredentials($credentials);
$service = new Google_Service_Calendar($client);
// $calendarId should contain the calendar id found on the settings page of the calendar
$calendarId = '*****myCalendarID*****';
$events = $service->events->listEvents($calendarId);
echo $events;
?>
</body>
</html>
Я помещаю файл test2.php в C: \ Apache24 \htdocs.
Когда я просматриваю: localhost / test2.php, браузер отображает:
This is a line of text in test2.php
Fatal error: Uncaught Error: Call to undefined method Google_Client::loadServiceAccountJson() in C:\Apache24\htdocs\test2.php:14 Stack trace: #0 {main} thrown in C:\Apache24\htdocs\test2.php on line 14
Почему бы не найти метод "loadServiceAccountJson"?Спасибо за просмотр.