我在尝试使用带有AWS Lambda函数调用的Google Calendar API创建日历事件时遇到问题。
AWS CloudWatch日志没有提供大量用于调试的信息。我对使用Google API非常陌生,无法弄清楚我的代码出了什么问题。
我正在使用的代码在这里:
from __future__ import print_function
from oauth2client import service_account
from apiclient import discovery
from oauth2client import client
from oauth2client import tools
from oauth2client.file import Storage
import httplib2
import boto3
import json
import logging
import requests
def lambda_handler(event, context):
logger = logging.getLogger()
logger.setLevel(logging.INFO)
ses = boto3.client('ses')
email_address = 'myemail@gmail.com' # change it to your email address
SCOPES = ['https://www.googleapis.com/auth/calendar']
SERVICE_ACCOUNT_FILE = 'aws-iot-f3edea2d0394.json'
credentials = service_account.ServiceAccountCredentials.from_json_keyfile_name(
SERVICE_ACCOUNT_FILE, scopes=SCOPES)
http = httplib2.Http()
http = credentials.authorize(http)
service = discovery.build('calendar', 'v3', http=http)
calendarId = 'myemail@gmail.com'
event = {
"summary": "aws iot test",
"location": "etc",
"description": "aws iot test - pushed from button",
"start": {
"dateTime": "2018-01-31T09:00:00-07:00",
"timeZone": "America/Los_Angeles"
},
"end": {
"dateTime": "2018-01-31T17:00:00-07:00",
"timeZone": "America/Los_Angeles"
}
}
event = service.events().insert(calendarId='primary', body=event).execute()
日历活动尚未创建,我无法弄清楚原因。我从AWS CloudWatch日志获取的唯一信息是最后一个事件:
[INFO] 2018-01-23T17:09:28.116Z 29b2e36a-0060-11e8-8c9e-1725945b009e URL being requested: POST https://www.googleapis.com/calendar/v3/calendars/primary/events?alt=json
这不是很有用。任何人都可以帮忙,让AWS给我更多信息,或者指出我在Python代码中做错了什么?谢谢!
答案 0 :(得分:0)
我能够找出问题所在。谷歌遗漏了整合工作所需的一些管理细节,我能够追踪到其他人在Google Calendar Api v3 asp.net Code 200, yet no event inserted遇到的类似问题。
原则上,您需要启用Google服务帐户才能更改日历。