我想访问 Google Calendar API 以使用 Python 插入条目。我创建了一个服务帐号在Google API控制台上,添加私钥,下载它。
但是,当我尝试修改同一帐户上的任何日历时,我收到以下错误消息。读书作品。
Code is
import httplib2
from oauth2client.client import SignedJwtAssertionCredentials
from apiclient.discovery import build
event = {
'summary' : 'Appointment',
'location' : 'Somewhere',
'start' : {
'dateTime' : '2012-09-03T10:00:00.000-07:00'
},
'end' : {
'dateTime' : '2012-09-03T10:25:00.000-07:00'
}
}
f = file("key.p12", "rb")
key = f.read()
f.close()
credentials = SignedJwtAssertionCredentials(
service_account_name='[email protected] /cdn-cgi/l/email-protection',
private_key=key,
scope='https://www.googleapis.com/auth/calendar'
)
http = httplib2.Http()
http = credentials.authorize(http)
service = build('calendar', 'v3', http=http)
request = service.events().insert(calendarId='[email protected] /cdn-cgi/l/email-protection', body=event)
response = request.execute()
print(response)
错误信息是:
apiclient.errors.HttpError: <HttpError 403 when requesting https://www.googleapis.com/calendar/v3/calendars/[email protected] /cdn-cgi/l/email-protection/events?alt=json returned "Forbidden">
我本以为我可以使用此服务帐户访问我自己的数据,但事实似乎并非如此。
谷歌声称
创建服务帐户后,您还可以访问
与私钥关联的客户端 ID。你将需要两者
在对应用程序进行编码时。 -https://developers.google.com/accounts/docs/OAuth2?hl=de#scenarios https://developers.google.com/accounts/docs/OAuth2?hl=de#scenarios
我用谷歌搜索了大约2个小时,但似乎记录得很糟糕。有没有一种方法可以通过 Google Calendar API 插入新事件而无需用户交互(又名 3 足 OAuth),或者有没有办法修复它?
我刚刚发现已弃用的 ClientLoging。为什么谷歌让它变得如此困难?
亲切的问候