Hany E
Hany E

Reputation: 97

Find Attendees of an Event

I am trying to display events from a "public" google calendar. My requirement is to get the number of attendees (not necessarily the names of the attendees). However, when I get the events using the Calendar API (using an API Key and CalendarID); the event is missing the whole attendees section that is mentioned here.

My question: Do I need to be authenticated ? Does this mean this can't be public, and the web-pages that displays this information will need the "viewer" to authenticate to Google first?

Here is a snippet of my code (edited)...

$.ajax({
  type: 'GET',
  url: encodeURI('https://www.googleapis.com/calendar/v3/calendars/' + calendarId+ '/events?key=' + myKey),
  dataType: 'json',
  success: function (response) {
    console.log(response);
    //here is where I need to get the number of participants
  },
  error: function (error) {
    console.log(error);
    //tell that an error has occurred
  }

Here is the output...

{kind: 'calendar#events', etag: '"p324e9j5nqabva0g"', summary: 'EDWC Schedule', description: '', updated: '2022-01-04T08:09:10.933Z', …} accessRole: 'reader' defaultReminders: (0) [] description: '' etag: '""' items: (2) [{…}, {…}] 0: {kind: 'calendar#event', etag: '""', id: '', status: 'confirmed', htmlLink:…} 1: {kind: 'calendar#event', etag: '""', id: '', status: 'confirmed', htmlLink:…} conferenceData: {} created: '' creator: {} description: '' end: {dateTime: '2022-01-08T16:00:00+11:00', timeZone: 'Australia/Sydney'} etag: '' eventType: 'default' hangoutLink: '' htmlLink: '' iCalUID: '' id: '' kind: 'calendar#event' location: 'Australia' organizer: {email: '', displayName: '', self: true} sequence: 0 start: {dateTime: '2022-01-08T13:00:00+11:00', timeZone: 'Australia/Sydney'} status: 'confirmed' summary: '' updated: '2022-01-04T08:09:10.933Z' [[Prototype]]: Object [[Prototype]]: Object length: 2 [[Prototype]]: Array(0) kind: 'calendar#events' nextSyncToken: 'CIjkzLfSl_UCEAAYASCvg6XIAQ==' summary: '' timeZone: 'Australia/Melbourne' updated: '2022-01-04T08:09:10.933Z' [[Prototype]]: Object

Upvotes: 4

Views: 488

Answers (2)

Jake Haller-Roby
Jake Haller-Roby

Reputation: 6427

You can accomplish this using the Google Api Node.js Client in this manner:

Google Calendar Event Attendees                                                                                 Run in Fusebit
const calendarClient = googleClient.calendar('v3');

// Update the below fields with your desired values
const calendarId = 'YOUR_CALENDAR_ID';
const eventId = 'YOUR EVENT_ID';

const response = await calendarClient.events.get({
  calendarId,
  eventId,
});

const attendees = response.data.attendees;

Upvotes: 2

Oriol Castander
Oriol Castander

Reputation: 648

  • As per your question, the answer is yes. Every request sent to the Google Calendar API must include an authorization token. Now, that authorization does not always entail a consent screen, it can also be a short-lived access token or an API key (like in your example). I would encourage you to read more about the authorization process here.
  • As per your code snippet and response, the events list is located inside the items property of the response object. Here you can find how the response object is structured, but in a nutshell, you can access the events by looping through the items like this:
for (var event of response['items']){}

Upvotes: 0

Related Questions