I am currently using Calendar API using Python to create a google calendar Event and send invitations to an attendee. Is there an Event link I can send to him by SMS? so that he could join it using that link also. The Calendar API gives the Event link in response but If I open it as Attendee. It says Event is not found.
My Code
from __future__ import print_function
import datetime
import os.path
from googleapiclient.discovery import build
from google_auth_oauthlib.flow import InstalledAppFlow
from google.auth.transport.requests import Request
from google.oauth2.credentials import Credentials
from google.oauth2 import service_account
# If modifying these scopes, delete the file token.json.
SCOPES = ['https://www.googleapis.com/auth/calendar','https://www.googleapis.com/auth/calendar.events',
'https://www.googleapis.com/auth/admin.directory.resource.calendar',
'https://www.googleapis.com/auth/gmail.send']
SERVICE_ACCOUNT_FILE = 'credentials.json'
def main():
"""Shows basic usage of the Google Calendar API.
Prints the start and name of the next 10 events on the user's calendar.
"""
creds = None
# The file token.json stores the user's access and refresh tokens, and is
# created automatically when the authorization flow completes for the first
# time.
creds =service_account.Credentials.from_service_account_file(SERVICE_ACCOUNT_FILE, scopes=SCOPES)
delegated_credentials = creds.with_subject('username@domain.com')
service = build('calendar', 'v3', credentials=delegated_credentials)
event = {
'summary': 'Driving Lessons 5',
'location': 'Location',
'description': 'Usman is Testing',
'start': {
'dateTime': '2022-08-27T09:00:00-07:00',
'timeZone': 'America/Los_Angeles',
},
'end': {
'dateTime': '2022-08-27T17:00:00-07:00',
'timeZone': 'America/Los_Angeles',
},
'recurrence': [
'RRULE:FREQ=DAILY;COUNT=1'
],
'attendees': [
{'email': 'attendee1@mail.com'},
{'email': 'attendee2@mail.com'},
],
'reminders': {
'useDefault': False,
'overrides': [
{'method': 'email', 'minutes': 24 * 60}
],
},
}
event = service.events().insert(calendarId='mycalenderid', body=event,sendUpdates='all').execute()
print ('Event created: %s' % (event.get('htmlLink')))
if __name__ == '__main__':
main()
Event link Generated when I run this code
If I copy and Paste this link in browser as an attendee, it says event not found.
The link you get in the response is the htmlLink
which will open successfully only with the account you're creating the event from, this contains specifically the event ID that was created in your calendar.
I did some research and unfortunately it seems there is no option with the Google Calendar API to generate an external event link or share a link by SMS, this feature was removed in 2019. You can always send a notification by email by adding the sendUpdates parameter in your code.
Now, the only workaround I found is sharing the link that you can generate directly from the event in the Google Calendar interface, click the three dots to the right, when clicking an event, and select "Publish event". The format to that link is:
https://calendar.google.com/event?action=TEMPLATE&tmeid=YOUR_EVENTID&tmsrc=add_the_attendee_email_address
However, if the attendee clicks on "Save" when openning the link you share, it will be created as a new event, this link is just like a template which means any changes the attendee makes it won't be reflected in your calendar.
If you have any questions let me know!