python dialogflow_如何在Python中通过Dialogflow实现从Google Assis...
最后,我解決了這個問題. @matthewayne發布的代碼有一些錯誤,例如它應該是“ POST”請求并更改一些有效負載和標頭參數,因此它起作用了!在這里,我更改了一些代碼并嘗試請求,并命中了通知!
import io
import json
import requests
from google.oauth2 import service_account
import google.auth.transport.requests
PATH_TO_SERVICE_ACCOUNT = 'path/to/json/service/account'
REQUIRED_SCOPE = 'https://www.googleapis.com/auth/actions.fulfillment.conversation'
# Get access token
with 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': '',
'intent': '',
# Expects a IETF BCP-47 language code (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_code) + ': ' + r.text)
總結
以上是生活随笔為你收集整理的python dialogflow_如何在Python中通过Dialogflow实现从Google Assis...的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: jtable.js 弹出框自适应高度
- 下一篇: 腾讯地图利用绘图工具测量距离