Python flask-ask中的Amazon Alexa主动事件请求 [英] Amazon Alexa Proactive Events request in Python flask-ask
问题描述
I am trying to make a request to the Proactive Events API by using the requests module of Python.
但是,我总是收到范围无效的响应。
有人可以帮忙吗?我究竟做错了什么?我的代码如下:
However I always receive a response that the scope is invalid. Can anyone help? What am I doing wrong? My code looks like this:
@ask.launch
def launch():
content_type = "application/x-www-form-urlencoded;charset=utf-8"
client_id = "amzn1.application-oa2-client.6a48XXXXXXX408"
client_secret = "592XXXXxxxxxxx6"
scope = "alexa::proactive_events"
grant_type = "client_credentials"
data = {"grant_type": grant_type, "client_id": client_id, "client_secret": client_secret, "scope": scope}
r = requests.post("https://api.amazon.com/auth/O2/token", data=data, headers={"content-type": content_type})
speech = render_template("welcome")
reprompt = render_template("welcome_reprompt")
return question(speech).reprompt(reprompt)
这是我得到的答复:
{'error_description': 'The request has an invalid parameter : scope', 'error': 'invalid_scope'}
推荐答案
Sinc出现无效范围的原因之一是您的技能清单中没有包含事件,因此我在此处提供了一些步骤。我发现使用SMAPI更新技能清单非常麻烦,所以我改用Ask cli。
Since one of the reason you get the invalid scope is that you dont have the events included in your skill manifest I include some steps here. I found quite cumbersome to use the SMAPI to update the skill manifest so instead I used ask cli.
- 安装ask-cli:获取授权代码为您的亚马逊帐户。在我的情况下,后端不是AWS Lambda函数,而是外部Web服务器
- 以json格式获取技能清单:
询问api get-skill -s amzn1.ask.skill.ZZZYYYZZ-阶段开发> skill.json
-
向清单中添加通知权限和事件元素:
- install ask-cli: get authorization code for your amazon acount. In my case the backend is not an AWS lambda function but an external web server
- get the skill manifest in json format:
ask api get-skill -s "amzn1.ask.skill.ZZZYYYZZ" --stage development > skill.json
Add the notifications permission and the events elements to the manifest:
{
name: alexa :: devices:all:notifications:write
}
和
事件:{
出版物:[
{
eventName: AMAZON.AAABBBCC
}
],
endpoint:{
uri: https:// XXXYYYZZ:443 / whatevercontext
}
}
更新清单:
询问api更新-skill -s amzn1.ask.skill.ZZZYYYZZ –阶段开发-f skill.json
- 在alexa应用程序中为您的特定技能启用通知
现在您应该能够获取令牌,下一步就是将通知发送到设备
Now you should be able to get the token and next step is to send the notification to the device
这篇关于Python flask-ask中的Amazon Alexa主动事件请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!