我使用以下代码要点成功检索日历活动参加者:
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] => [email protected] /cdn-cgi/l/email-protection
[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 日历用户创建的活动详细信息
我看不到您如何创建相关事件,但我的猜测是,当创建事件并且与会者添加其显示名称时,并未将其作为可选参数插入。
事件.插入 https://developers.google.com/google-apps/calendar/v3/reference/events/insert
attendees[].displayName string 与会者的姓名(如果有)。选修的。可写
通过 Google 日历网络视图创建活动时,您只需添加用户电子邮件地址。如果所述用户是 Gmail 帐户,则 Google 可以猜测显示名称。如果它不是 Gmail 帐户,那么 google 就无法知道用户名是什么,因为您最终的显示名称为空。
attendees": [
{
"email": "[email protected] /cdn-cgi/l/email-protection",
"displayName": "Linda Lawton",
"organizer": true,
"self": true,
"responseStatus": "accepted"
},
{
"email": "[email protected] /cdn-cgi/l/email-protection",
"responseStatus": "needsAction"
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)