Read Google calendar

I had forgotten that getEvents() did not return a viewable array, you have to dig deeper in each event!

This script should return a stringified list of lists of all events that match. Just put an empty string for search to return all events between the two dates. The search is not case sensitive (you can search for dog where an event contains Dog)

function doGet(e){
  
  var returnEvents = [];
  var cal = CalendarApp.getCalendarById(e.parameter.calId);
  var events = cal.getEvents(new Date(e.parameter.startDate), new Date(e.parameter.endDate),{search:e.parameter.search});
  for (var i = 0; i<events.length; i++) {
   returnEvents.push([events[i].getTitle(),events[i].getLocation(),events[i].getDescription()]); 
  }
  return ContentService.createTextOutput(JSON.stringify(returnEvents));

}

Note the calendar service has not been completely reliable for me while testing, e.g. not always returning all results, this is between the apps script and the calendar, nothing to do with App Inventor.

Also, I left out the word return in the last part of the script earlier, sorry about that.

Unfortunately it doesn't work.

function doGet(e){
  
  var returnEvents = [];
  var cal = CalendarApp.getCalendarById(e.parameter.calId);
  var events = cal.getEvents(new Date(e.parameter.startDate), new Date(e.parameter.endDate),{search:e.parameter.search});
  for (var i = 0; i<events.length; i++) {
   returnEvents.push([events[i].getTitle(),events[i].getLocation(),events[i].getDescription()]); 
  }
  return ContentService.createTextOutput(JSON.stringify(returnEvents));

}

I tried to add a Listview to contain the result of WEB1.get, but the error is the following:

The error is about the format of the Google Calendar response which is in HTML not JSON, right?
Another question, the WEB1.got answer where should it be contained? Listview?

Check your script url in your app matches the latest deployed script on Google

Before trying the app working with your changes, I deployed the script and copied the new URL.

You are getting a 400 error code which indicates that the script page you are calling does not exist

To start with, put your response into a label or textbox so that you can easily see what is coming back

This is the error.


Check that your script does have the return before ContentService and that you have correctly published and deployed your script, and that you are using the correct script url.

Failing that post your aia project here (or via private message) with a screenshot of your script project and the deployment message which includes the script url.

Assuming you have a single event in the time frame set in your calendar that returns:

[["Title_01","Location_01","description_01"]]

it is working fine here...

Have you tried with emulator or companion?
I have tried with both but it gives me the same error.

EDIT: with compagnion work fine. now I have to put the results in a listview divided by appointment. How can I do?

Pleased to hear you finally got it working.

To display in listview:
Let us say your calendar query returns three events, so that you have this in your events lists

[["Title_01","Location_01","description_01"],
["Title_02","Location_02","description_02"],
["Title_03","Location_03","description_03"]]

You can use these blocks to display each event:
image
like this:
image

I have deleted your post containing your script/aia so that you can safely continue to use that calendar

2 Likes

I like JOIN WITH SEPARATOR \n
for each row in cases like this.

2 Likes

I keep forgetting about that block :upside_down_face:

image

3 Likes

A really big thank you for the help and availability shown! you allowed me to implement my app! Thanks again!
If you need the ".aia" file for a guide, I'm super helpful!
See you next adventure! :wink:

Hi Tim,
I need to export the selected index inside a textbox.
The division should be (e.g.):
Title_01: Textbox1
Location_1: Textbox2
Description_01: Textbox3

Can you help me?


Use the events list created when the events are returned from Google Calendar, because this is in list format, and the selection index from the list view, then select each item.

Alternatively you could use the text split by block to split the listvew selection to a list, the delimiter should be \n

1 Like