Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 336
gospodin Avatar asked Sep 06 '25 03:09

gospodin


2 Answers

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:

  • DateTime
  • UpdatedMin Error1
  • UpdatedMin Error2
  • Calendar.Events.List
like image 130
NightEye Avatar answered Sep 07 '25 22:09

NightEye


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.

like image 44
mary Avatar answered Sep 07 '25 22:09

mary