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

如何在Python中通过Dialogflow实现从Google Assistant发送推送通知

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

如何在Python中通过Dialogflow实现从Google Assistant发送推送通知

最后解决了问题。@matthewayne发布的代码有一些错误,例如,请求必须是“
POST”方法,并且需要更改有效负载和标头中的某些参数,因此它起作用了!在这里,我更改了一些代码并尝试请求和它打了一个通知!

我参考了此文档以使其起作用!

import ioimport jsonimport requestsfrom google.oauth2 import service_accountimport google.auth.transport.requestsPATH_TO_SERVICE_ACCOUNT = 'path/to/json/service/account'REQUIRED_SCOPE = 'https://www.googleapis.com/auth/actions.fulfillment.conversation'# Get access tokenwith io.open(PATH_TO_SERVICE_ACCOUNT, 'r', encoding='utf-8') as json_fi:    credentials_info = json.load(json_fi)credentials = service_account.Credentials.from_service_account_info(    credentials_info, scopes=[REQUIRED_SCOPE])request = google.auth.transport.requests.Request()credentials.refresh(request)headers = {    'Authorization': 'Bearer ' + credentials.token}payload = {    'customPushMessage': {        'userNotification': { 'title': 'Notification title', 'text': 'Simple Text'        },        'target': { 'userId': '<USER_ID>', 'intent': '<INTENT>', # Expects a IETF BCP-47 language pre (i.e. en-US) 'locale': 'en-US'        }    }}r = requests.request("POST", 'https://actions.googleapis.com/v2/conversations:send', data=json.dumps(payload), headers=headers)print(str(r.status_pre) + ': ' + r.text)


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

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

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