Read Google calendar

Hello Folks,
I would like to have on my app the Google Calendar with appointments etc ...
I would also like to "download" the appointment and fill in some predefined TextBoxes.
How can I do?

also

1 Like

Thanks for reply.
I need to read the appointment and transfer it to a list not generate an appointment.

https://developers.google.com/apps-script/reference/calendar/calendar-app#getEvents(Date,Date,Object)
1 Like

Sorry, I can't figure out what to do. Can you give me an example?

What is it that you do not understand?

I am unable to create a script from the beginning.
I am also unable to create the block routine from the beginning. Sorry.

Maybe these will help:

1 Like

I would like to create a direct reading between AI2 and Google Calendar. The links you posted to me talk about GSheet which I don't use.
I'll explain the project:
when I push the button the appointment data in GCalendar is transmitted to a list. Below with afterpicker I would like the chosen data to fill some textboxes.
Can you help me make this?

The above links were provided to help you with this:

and are just examples, not a direct solution.

You will need to create a google apps script web app that runs the getEvents(...) routine to return ALL events within a specific time frame that match a certain search criteria. Once the script has done this it should return a stringified json list to your app.

The apps script which is created using your specified google account, must have shared access to the calendar you want to use

Your app blocks will use the web component to make the call to the web app, and handle the return data, to apply to your textboxes....

1 Like

Okay, I have several calendars to read.
I would like to insert the calendar ID into AI2 and insert it into the script.
Regarding the script arguments I need you to give me examples with other scripts in order to be able to make mine.

I find in web this code but work with GSheet.

function getEvents(){
  var ss = SpreadsheetApp.getActiveSpreadsheet();
  var sheet = ss.getSheetByName("GetEvents");

  var cal = CalendarApp.getCalendarById("aryanirani123@gmail.com");
  var events = cal.getEvents(new Date("6/27/2021 12:00 AM"), new Date("6/30/2021 11:59 PM"));

  for(var i = 0;i<events.length;i++){
    var title = events[i].getTitle();
    var start_time = events[i].getStartTime();
    var end_time = events[i].getEndTime();
    var loc = events[i].getLocation();
    var des = events[i].getDescription();

    sheet.getRange(i+2,1).setValue(title);
    sheet.getRange(i+2,2).setValue(start_time);
    sheet.getRange(i+2,3).setValue(end_time);
    sheet.getRange(i+2,4).setValue(loc);
    sheet.getRange(i+2,5).setValue(des);
  }

  Logger.log("Events have been added to the Spreadsheet");
}

How do I transform the code that can work with AI2 without Gsheet?

Something like this:

function doGet(e){
  
  var cal = CalendarApp.getCalendarById(e.parameter.calId);
  var events = cal.getEvents(e.parameter.startDate, e.parameter.endDate, {search: e.parameter.search});

  ContentService.createTextOutput(JSON.stringify(events));

}

Your AI2 app will need to send four parameters: calId,startDate,endDate,search.

You will need to ensure that the dates you send are in the correct format.

For the dates it may be easier to do it like this:

new Date(e.parameter.startDate)

where the parameter startDate = "6/27/2021 12:00 AM" << a string not a date number

Ok, I created script and i deploy.
Now block image is
blocks (4)

How insert e.parameter with text box?
How I create the list when Web1GotText?

Something like this:

Not work, where is the error?

This looks wrong:
image
Look in your calendar settings for the calendar ID, it is not a url.
image

There are no parameters in the gotEvents(..) for these two items that you added...
image

Did you edit your script to include new Date(..) before the startDate and endDate parameters ? e.g.

var events = cal.getEvents(new Date(e.parameter.startDate), new Date(e.parameter.endDate),....

and then redeploy your script using the method provided in one of my links?

This is the code.
I redistributed correctly as indicated in your links.

function doGet(e){
var cal = CalendarApp.getCalendarById(e.parameter.calId);
var events = cal.getEvents(new Date(e.parameter.startDate), new Date(e.parameter.endDate), e.parameter.title, e.parameter.description, e.parameter.location, {search: e.parameter.search});

ContentService.createTextOutput(JSON.stringify(events));
}

Then the block now is:

App not work.

Yep, script needs more work. Will look at this later.

What data for each event do you want returned ?

I need to read Title, address, description.
Thanks.