gpt4 book ai didi

python - Google Calendar API - 服务帐户 - 没有 Google Apps 域

转载 作者:太空宇宙 更新时间:2023-11-03 17:58:40 25 4
gpt4 key购买 nike

是否可以在没有 Google Apps 域的情况下将 Google Calendar API v3 与服务帐户一起使用?

基本上我想做的是使用 python 脚本在我自己的日历上创建一个事件,而无需脚本提示我输入用户名和密码...有人知道吗?

我使用了这段代码,但没有运气:

import pprint
import pytz
import httplib2
import requests

from datetime import datetime, timedelta
from apiclient.discovery import build
from oauth2client.client import SignedJwtAssertionCredentials

with open('/home/xpto/service_account_certificate.pem', 'rb') as f:
key = f.read()

service_account_name = '000000000000-j...@developer.gserviceaccount.com'

credentials = SignedJwtAssertionCredentials(
service_account_name,
key,
scope=['https://www.googleapis.com/auth/calendar',
'https://www.googleapis.com/auth/calendar.readonly'],
sub='xpto@gmail.com')

http = httplib2.Http()
http = credentials.authorize(http)

service = build(serviceName='calendar', version='v3', http=http)

我收到此错误:

auth2client.client.AccessTokenRefreshError:unauthorized_client:请求中未经授权的客户端或范围

最佳答案

是 - 只需创建一个服务帐户,这将为您提供该帐户的电子邮件地址。

然后只需与该电子邮件地址共享您的日历,并为其提供所需的任何权限。

关于python - Google Calendar API - 服务帐户 - 没有 Google Apps 域,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28074276/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com