Reputation: 91
When retrieving events using the Google Calendar Api v3 the attendees array is not included in the results. I'm authenticating with a service account, so there should be no access restrictions on individual fields.
My request looks like this (authentication code omitted for brevity):
async function fetchEvents() {
const calendar = google.calendar('v3')
google.options({ auth: await auth() })
return await calendar.events.list({
calendarId:
'<the-actual-calendar-id>@group.calendar.google.com',
fields:
'items(summary,description,attendees)',
maxAttendees: 99,
timeMin: new Date().toISOString(),
maxResults: 5,
singleEvents: true,
orderBy: 'startTime'
})
}
Omitting the fields
parameter entirely also doesn't include the attendees although the field is part of the Events Resource.
Likewise, omitting maxAttendees
also doesn't change anything.
Following the htmlLink returned from the API, I can verify that a particular event has a list of attendees.
Upvotes: 0
Views: 1049
Reputation: 91
As pointed out in DalmTo's answer an event's attendees is a privileged field that can't be retrieved with a service account unless it is used to impersonate the calendar's owner.
Enable domain-wide delegation for the service account in the Admin Console. The OAuth scope required is https://www.googleapis.com/auth/calendar.events
.
Use google.auth.JWT
to impersonate the user (from this GitHub issue):
const auth = google.auth.JWT({
subject: '[email protected]',
keyFile: '/path/to/service-account-keyfile.json',
scopes: ['https://www.googleapis.com/auth/calendar.events']
})
const calendar = google.calendar({ version: 'v3', auth })
const { data } = await calendar.events.list({ ... })
Upvotes: 1
Reputation: 116868
Sounds like you have not set up delegation properly. When you delegate to the user in your workspace domain. That user has access on the domain for the-actual-calendar-id>@group.calendar.google.com
Then you init impersonation with the with_subject .
from google.oauth2 import service_account
SCOPES = ['https://www.googleapis.com/auth/calendar']
SERVICE_ACCOUNT_FILE = '/path/to/service.json'
credentials = service_account.Credentials.from_service_account_file(
SERVICE_ACCOUNT_FILE, scopes=SCOPES)
delegated_credentials = credentials.with_subject('[email protected]')
Upvotes: 1