通过短信发送谷歌事件链接(日历API)



我目前正在使用日历API,使用Python创建google日历事件并向与会者发送邀请。有没有我可以通过短信发送给他的活动链接?以便他也可以使用该链接加入。日历API提供事件链接作为响应,但如果我以与会者身份打开它。上面写着找不到Event。

我的代码

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()

运行此代码时生成的事件链接

https://www.google.com/calendar/event?eid=OHY5M3JlcmRzZ2RoM2tvMnZuZHQ0dXB1MDRfMjAyMjA4MjdUMTYwMDAwWiB1c21hbkBkcml2aW9sb2d5LmNvbQ

如果我作为与会者在浏览器中复制并粘贴此链接,它会显示找不到事件。

您在响应中获得的链接是htmlLink,它只有使用您创建事件的帐户才能成功打开,其中特别包含在日历中创建的事件ID。

我做了一些研究,不幸的是,谷歌日历API似乎没有生成外部事件链接或通过短信共享链接的选项,该功能于2019年被删除。通过在代码中添加sendUpdates参数,您可以随时通过电子邮件发送通知。

现在,我找到的唯一解决方法是共享链接,您可以直接从谷歌日历界面中的事件生成链接,在单击事件时单击右侧的三个点,然后选择"发布事件";。该链接的格式为:

https://calendar.google.com/event?action=TEMPLATE&tmeid=YOUR_EVENTID&tmsrc=add_the_attendee_email_address

然而,如果与会者点击";保存";当打开你共享的链接时,它将被创建为一个新的活动,这个链接就像一个模板,意味着与会者对它所做的任何更改都不会反映在你的日历中。

如果你有任何问题,请告诉我!

最新更新