Does anyone have an example of working with google calendar events? Or could give some advise on this. I find googles API documentation very confusing.
I’d like to create a booking system that creates an event in my calendar and invites the logged in google user as a guest to the event.
I’ve done a similar app already but the final outcome is sending an email confirming the time. I think it would be better to create a google event. I work with a school that uses the google suite.
Did you ever get anywhere with this? I’m thinking about doing something very similar.
stucork
October 18, 2020, 1:37am
#3
Yes - I ended up writing a guest post recently where I used some integrations with google calender to create a Calendly style app
How long does it take to prototype a startup? I found out by rebuilding a working version of Calendly, the invaluable meeting scheduling app.
And the answer is that you can be really fast, if you use the right tools.
When I was playing with the google calendar integration I basically went to googles api reference docs e.g.
https://developers.google.com/calendar/v3/reference/freebusy/query
came up with some http requests and tested them in google’s ‘Try this API’ feature.
Then used anvil’s http request library to make the requests
https://anvil.works/docs/http-apis/making-http-requests
e.g. to get the busy times in my calendar I would use google’s api reference above and adapt it to anvil
url = 'https://www.googleapis.com/calendar/v3/freeBusy'
response = anvil.http.request(url,
json=True,
method='POST',
headers={
'Authorization': 'Bearer ' + access_token
},
data = {
"timeMin": timeMin.isoformat(),
"timeMax": timeMax.isoformat(),
"items": [
{
"id": user['email']
}
],
"timeZone": user['timezone']
}
)
which is very similar to the example given in google references:
I also had to follow https://anvil.works/docs/integrations/google/linking-google-and-anvil
to connect to google.
Requests were preceded by gaining an access token
refresh_token = anvil.secrets.decrypt_with_key('token_key', user['refresh_token'])
access_token = anvil.google.auth.refresh_access_token(refresh_token)
Having gained user permissions on the very first sign up:
# Client side
email = anvil.google.auth.login(['https://www.googleapis.com/auth/calendar'])
if email:
anvil.server.call('create_user')
# Server side
@anvil.server.callable
def create_user():
refresh_token = anvil.google.auth.get_user_refresh_token()
token = anvil.google.auth.get_user_access_token()
email = anvil.google.auth.get_user_email()
4 Likes
Excellent! Thank you kindly.
Stu this is very cool! I might be “borrowing” some of this… Thank You
1 Like
This is great. I really like what you did there!
1 Like