【发布时间】:2017-02-06 18:36:58
【问题描述】:
我正在使用以下代码要点成功检索日历活动参与者:
require_once __DIR__ . '/vendor/autoload.php';
putenv("GOOGLE_APPLICATION_CREDENTIALS=" . __DIR__ . '/mt-service-account.json');
$client = new Google_Client();
$client->useApplicationDefaultCredentials();
$client->setApplicationName("APP NAME");
$client->setSubject("<APPROPRIATE_USER_EMAIL>");
$client->setScopes([
'https://www.googleapis.com/auth/calendar'
]);
$calendarService = new Google_Service_Calendar($client);
$optParams = array(
'singleEvents' => true,
'orderBy' => 'startTime'
);
$events = $calendarService->events->listEvents('<APPROPRIATE_CALENDAR_ID>', $optParams);
foreach ($events->getItems() as $event) {
print_r($event->getAttendees());
}
但是,从响应中可以看出,没有返回显示名称。
Array
(
[0] => Google_Service_Calendar_EventAttendee Object
(
[additionalGuests] =>
[comment] =>
[displayName] =>
[email] => johnsmith@domain.com
[id] =>
[optional] =>
[organizer] =>
[resource] =>
[responseStatus] => needsAction
[self] =>
[internal_gapi_mappings:protected] => Array
(
)
[modelData:protected] => Array
(
)
[processed:protected] => Array
(
)
)
)
有问题的与会者是活动创建者的联系人,在创建活动时,联系人的姓名和电子邮件会出现在类型辅助字段中。
UPDATE NB 事件不是通过 API 创建的。它们是通过 Google 日历(即在浏览器中)创建的。通过在“添加与会者”字段中键入与会者的姓名来添加与会者(Google 类型助手找到了联系人)。目的是以编程方式(即使用 API)检索由 G Suite 日历用户创建的事件详细信息
【问题讨论】:
-
4 年后,我也遇到了同样的问题。 @Jordan 你知道了吗?