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

Google服务帐户无法模拟GSuite用户

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

Google服务帐户无法模拟GSuite用户

我认为您的问题是,在调用Calendar
API
之前,您没有对凭据进行授权,但是我在自己的实现中使用了一些区别

  • 使用以下导入语句

    from oauth2client.service_account import ServiceAccountCredentials

    from apiclient import discovery

  • 使用

    from_json_keyfile_name
    方法

  • 授权凭证,并

    http
    在构建服务时将其作为参数传递

尝试对您的代码进行此修改:

from apiclient import discoveryfrom oauth2client.service_account import ServiceAccountCredentialsimport httplib2SCOPES = ['https://www.googleapis.com/auth/calendar']SERVICE_ACCOUNT_FILE = 'GOOGLE_SECRET.json'credentials = ServiceAccountCredentials.from_json_keyfile_name(        SERVICE_ACCOUNT_FILE, scopes=SCOPES)# Use the create_delegated() method and authorize the delegated credentialsdelegated_credentials = credentials.create_delegated('address@example.com')  delegated_http = delegated_credentials.authorize(httplib2.Http())google_calendar = discovery.build('calendar', 'v3', http=delegated_http)events = google_calendar.events().list(    calendarId='address@example.com',    maxResults=10).execute()

我也建议

calendarId='primary'
您在API调用中进行设置,以便始终返回当前为其委派了凭据的用户的主日历。

有关使用进行身份验证的更多信息,

ServiceAccountCredentials
请参见以下链接:http
:
//oauth2client.readthedocs.io/en/latest/source/oauth2client.service_account.html



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

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

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