How to Insert Event in Google Calendar

Did you skip some steps in your post here? I’ve tried this and several different variations with no success.

Thanks

In Whose calendar do you want events inserted? Yours or your users?

It’s a lot easier to add it to yours than others calendars.

But, setup oauth and sky’s the limit.

https://x.thunkable.com/projectPage/61e4e200e0ca1b001138c8b3

Here’s one way of doing it ^^^^

This example only GETs cal events but does so as an authenticated user. Get this far and I can show you how to create events for any user who gives your app permission!

2 Likes

I have also never had success with google app script , @overshield . But here is another approach - How to set Reminder Notifications with Zapier in Thunkable X? - YouTube

I’m wanting users to be able to add or remove to my calendar only.

I suppose it might be an added benefit to allow users to update their calendar also, but that’s assuming they use google calendar.

But again primarily just needs to be my calendar to add appointments, if they cancel their appointments in app it should delete the event too.

Currently my users can cancel appointments so I just need to add the delete event it seems.

1 Like

There’s also share links that google provides. A link that when clicked allows users to add events to their calendar. Might work for you. Gonna try to dig that up today!

2 Likes

See this

1 Like

I saw this one, but it does allow the user to edit the calendar which could cause problems, is there a way to use this link and execute it or does it require that final step to confirm?

1 Like

Use Google Apps Script

Example

function addEvents() {
   return CalendarApp.getDefaultCalendar().createEventFromDescription('test event, today 9AM');
 }

If you add this to your script and call this function, it will add an event to your calendar.

1 Like

Ok I got this to work via my google script screen and it did in fact create the event in my calendar, the first time I ran it, it failed, then I clicked run again and it sent me to the auth page to allow it. It also said it hasn’t been verified by google but I proceeded anyway, once I did all of that it created the event.

How do I call this function from the app?
Here’s what I’ve got so far…

1 Like

To run it from Thunkable you need to first Deploy it to the Web. However, to pass any parameters to it you need to wrap it in doGet function.

This is typical with every GAS (Google Apps Script) function.

1 Like

I went ahead and deployed it and got the macro/s/***/exec URL

I’m not sure how to wrap that into a doGet function though

1 Like

See this tutorial. It is for saving Canvas image to GDrive but will give you insight of how to use doGet/doPost to pass parameters from Thunkable to GAS.

1 Like

Ok I have the following, works from inside the google web page, but I must have something wrong in the app. I’m getting a 401 status


Is this correct with the doPost in the object component?

1 Like

Your Thunkable blocks should only pass the text of the event.

image

Your function will then be something like this.

function doPost(event) {
   return CalendarApp.getDefaultCalendar().createEventFromDescription(event.parameters.eventDesc);
 }
1 Like

I thought you edit the date and time from that text box. But you are saying only the description?

1 Like

There are many functions in the calendar object. I’m using here the function createEventFromDescription so you need to pass description such as:
Thunkable advanced meeting 10AM. The function will parse the description and create a meeting event from it.

You could see the list of functions and choose the one that fits your need.

1 Like

I now have the following but I’m not getting a calendar event

function doPost(event) {
   return CalendarApp.getDefaultCalendar().createEventFromDescription(event.parameters.eventDesc);
 }

1 Like

You need to first execute it from the script editor to process the authentication process then it will work.

Have you done this step?

1 Like

Yes I did, I had to do it twice like the one before.
Getting this error when I try, makes sense though bc I haven’t really defined it in the script.

1 Like

Google want to confuse the rest of us by having both parameter and parameters. Check with one works for you

2 Likes