Why is Display Name is not Showing in Calendar Event Attendees?

空扰寡人 提交于 2019-12-23 01:46:10

问题


I'm successfully retrieving Calendar Event Attendees using the following code 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());
}

However, as can be seen in the response, no Display Name is returned.

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

        )
)

The attendee in question is a Contact of the event creator and the Contact's name and email appear in the type assist field when creating an event.

UPDATE NB Events are not created via API. They're created via Google Calendar (i.e. in browser). The attendees are added by typing the attendee's name in the Add Attendee field (Google type-assist found the Contact). The aim is to retrieve programmatically (i.e. with API) event details created by our G Suite Calendar users


回答1:


I cant see how you are creating the event in question but my guess is that when the event was created and the attendee added their display name was not inserted as an optional parameter.

Events.insert

attendees[].displayName string The attendee's name, if available. Optional. writable

When events are creted via the Google Calendar web view you just add a users Email address. In the event that said user is a Gmail account then Google can guess the display name. In the event it is not a Gmail account then google has no way of knowing what the users name is there for you end up with a display name of null.

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


来源:https://stackoverflow.com/questions/42065049/why-is-display-name-is-not-showing-in-calendar-event-attendees

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!