为什么显示名称未在日历事件参加者中显示?

时间:2017-02-06 10:05:47

标签: google-calendar-api

我使用以下代码gist成功检索了日历事件参与者:

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
                (
                )

        )
)

相关与会者是活动创建者的联系人,在创建活动时,联系人的姓名和电子邮件会显示在类型辅助字段中。

更新 NB 事件不是通过API创建的。它们是通过Google日历(即在浏览器中)创建的。通过在“添加与会者”字段中键入与会者姓名来添加与会者(Google type-assist找到了联系人)。目的是以编程方式(即使用API​​)检索由我们的G Suite日历用户创建的事件详细信息

1 个答案:

答案 0 :(得分:0)

我无法看到你是如何创建有问题的事件的,但我的猜测是,当事件创建并且与会者添加了他们的显示名称时没有作为可选参数插入。

Events.insert

  

与会者[] .displayName字符串与会者的姓名(如果有)。可选的。可写

通过Google日历网络视图创建活动时,您只需添加用户电子邮件地址即可。如果所述用户是Gmail帐户,则Google可以猜出显示名称。如果它不是Gmail帐户,那么谷歌无法知道用户名是什么,最终显示名称为null。

attendees": [
    {
     "email": "lme@gmail.com",
     "displayName": "Linda Lawton",
     "organizer": true,
     "self": true,
     "responseStatus": "accepted"
    },
    {
     "email": "ll@meAtWork.com",
     "responseStatus": "needsAction"
    }