这段代码(使用Google PHP API Client https://github.com/googleapis/google-api-php-client)回答“No upcoming events found.",显然没有检索事件,因为日历中至少有一个未来事件。
index.php
require_once __DIR__.'/vendor/autoload.php';
session_start();
putenv('GOOGLE_APPLICATION_CREDENTIALS=XXX.json');
$client = new Google\Client();
$client->useApplicationDefaultCredentials();
$client->addScope('https://www.googleapis.com/auth/calendar.events.readonly');
$calendarId = 'primary';
$optParams = array(
'maxResults' => 10,
'orderBy' => 'startTime',
'singleEvents' => TRUE,
'timeMin' => date('c'),
);
$service = new Google_Service_Calendar($client);
$results = $service->events->listEvents($calendarId, $optParams);
if (count($results->getItems()) == 0) {
print "No upcoming events found.\n";
} else {
print "Upcoming events:\n";
foreach ($results->getItems() as $event) {
$start = $event->start->dateTime;
if (empty($start)) {
$start = $event->start->date;
}
printf("%s (%s)\n", $event->getSummary(), $start);
}
}
我将我的www.example.com添加XXX@XXX.iam.gserviceaccount.com到可以访问我的日历事件详细信息的人员列表中,但没有任何变化。我仍在尝试检索Google日历事件列表,而不需要OAuth(服务帐户服务器到服务器)。
1条答案
按热度按时间yyyllmsg1#
请确保已配置域范围的委派,并将主题设置为域中要模拟的用户。