栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

Google Calendar与Django集成

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

Google Calendar与Django集成

此处仅需注意:尽管代码可以正常工作,但按照https://github.com/googleapis/google-auth-library-
python/blob/7a8641a7f0718c0dce413436f23691e8590face1/docs/index.rst的规定
,oauth2client最近已被弃用,而支持google-
身份验证库-https: //github.com/googleapis/google-auth-library-
python/tree/edfe24602051969e32917e82bcedd2bace43e260

您可以在这里找到新库的文档-https: //google-auth.readthedocs.io/en/latest/user-
guide.html

要使用新库,可以将代码编写为

import datetimefrom datetime import timedeltaimport pytzfrom google.oauth2 import service_accountfrom googleapiclient.discovery import buildservice_account_email = "app-calendar@xxxxxxxxx.iam.gserviceaccount.com"SCOPES = ["https://www.googleapis.com/auth/calendar"]credentials = service_account.Credentials.from_service_account_file('google_calendar_credential.json')scoped_credentials = credentials.with_scopes(SCOPES)def build_service():    service = build("calendar", "v3", credentials=scoped_credentials)    return servicedef create_event():    service = build_service()    start_datetime = datetime.datetime.now(tz=pytz.utc)    event = (        service.events()        .insert( calendarId="primary", body={     "summary": "Foo 2",     "description": "Bar",     "start": {"dateTime": start_datetime.isoformat()},     "end": {         "dateTime": (start_datetime + timedelta(minutes=15)).isoformat()     }, },        )        .execute()    )    print(event)create_event()

由于我的信誉不足,无法将其发布为评论,因此将其发布为单独的帖子



转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/431477.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号