Reputation: 159
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] => [email protected]
[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
Upvotes: 3
Views: 4503
Reputation: 116968
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.
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": "[email protected]",
"displayName": "Linda Lawton",
"organizer": true,
"self": true,
"responseStatus": "accepted"
},
{
"email": "[email protected]",
"responseStatus": "needsAction"
}
Upvotes: 1