gospodin
gospodin

Reputation: 1201

Get the list of created Google Calendar events for a specific user

I was trying to get the number of events that a specific user created in the past month using Google Calendar API.

The problem is that I got all the events where a user was invited. I don't see how to query only the events that user created.

calendarId: user's email adress updatedMin : today - one month

I am using Google's api explorer to query Calendar API.

Upvotes: 4

Views: 1405

Answers (2)

mary
mary

Reputation: 721

Include a query parameter in your request:

q: [email protected]

This will filter to only events organized by [email protected].

Updated:
Unfortunately the query parameter does not accept key value pairs. This solution will not work.

Upvotes: 1

NightEye
NightEye

Reputation: 11194

You can filter them by creator.email or organizer.email

Code:

function getCreatedEvents() {
  var user = '[email protected]';
  var today = new Date();
  var date = new Date();
  date.setMonth(date.getMonth() - 1);
  
  var args = {
    timeMin: new Date(date.getTime()).toISOString(),
    timeMax: new Date(today.getTime()).toISOString()
  }
  var events = Calendar.Events.list(user, args).items;

  events.forEach(function (event){
    if(event.creator && event.creator.email == user){
      // do something to events
      Logger.log(event);
    }
  });
}

Output:

output

References:

Upvotes: 1

Related Questions