我正在尝试构建一个应用程序以通过对话框流全功能向用户发送推送通知。我点击了this链接,现在我获得了更新许可(请参阅问题底部的屏幕快照1和2)。我按照stackoverflow thread编写此python代码来发送通知,我能够运行它,并获得状态码200,但我从未在GoogleHomeApp / Google扬声器上收到测试通知。你能帮忙吗?
import io
import json
import requests
from google.oauth2 import service_account
import google.auth.transport.requests
PATH_TO_SERVICE_ACCOUNT = 'account.json'
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
}
text = 'Hello, this is a test notification'
user_id = "ABwppHFyNFT1fqDRmEug_k2ZKu43hM7xbLmgShN_ESww0iwPLQh-BU6n4T-e3rUOiVqRBWNn5q6bOg"
payload = {
'customPushMessage': {
'userNotification': {
'title': 'Recent News',
'text': text,
},
'target': {
'userId': user_id,
'intent': 'Recent News',
# 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(f"A push notification has been sent to user {user_id} with status code {r.status_code}.")
这是我在本地主机上获得的日志,表明我有权向用户发送推送通知。
我去了堆栈驱动程序日志以检查日志,这就是我得到的内容:
如果转到Official Push Notifications Documentation,您会发现说明,表明现在为止,[voice-activated speakers上的不支持推送通知。
很快他们可能会发布更新,但我们永远不知道!您可以向支持团队询问有关更新的信息。