【发布时间】:2021-06-27 16:03:39
【问题描述】:
我正在尝试使用谷歌推送通知来通知用户活动的开始或/和结束日期时间是否发生变化。
我已按照push doc 中关于注册和验证我的域的所有步骤进行操作。
我的代码如下:
@blueprint.route("/notifications", methods={'GET','POST'})
def timeBlocker():
email = '....@gmail.com'
user = User.query.filter_by(email=email).first()
thecredentials = {
'client_id': os.getenv('client_id'),
'client_secret':os.getenv('client_secret'),
'refresh_token':user.refresh,
'grant_type': 'refresh_token',
}
req = requests.post(url='https://oauth2.googleapis.com/token', data = thecredentials)
req_ = req.json()
accessToken = req_["access_token"]
print('access token is ' + accessToken)
body = {
'id': '01234567-89ab-cdef-0123456789ab',
'type': 'web_hook',
'address': 'https://dayliii.com/notifications'
}
headers = {'Authorization': 'Bearer ' + accessToken,
'Content-Type': 'application/json'
}
calendar = '....@group.calendar.google.com'
req = requests.post(url='https://www.googleapis.com/calendar/v3/calendars/....@group.calendar.google.com/events/watch', data = body, headers=headers)
return str(req.json())
错误:
{'error': {'errors': [{'domain': 'global', 'reason': 'parseError', 'message': 'Parse Error'}], 'code': 400, 'message ': '解析错误'}}
我尝试将双引号转换为单引号,因为 similar post suggested 但它不起作用。
最后,我很想知道在开发模式下使用推送通知时是否应该注册并验证“http://localhost:5000/”的域所有权?因为这是我期望得到的错误,所以不确定如何解决它。
【问题讨论】:
标签: google-api google-calendar-api google-api-client google-api-python-client