我目前正在努力将Amazon Alexa与我们当前的系统进行集成。我必须做的TL;DR版本是,我应该能够通过Alexa skill Management API以编程方式创建Alexa技能。
虽然这很简单,但我在身份验证阶段遇到了障碍(这涉及到使用Amazon登录):
这种方法的工作原理是,您对SMAPI端点发出的每个请求都必须在Authorization HTTP头中包含授权令牌。
假设我使用下面的主体向https://api.amazonalexa.com/v0/skills发出POST请求:
{
"vendorId":"my-vendor-id",
"skillManifest": {
"publishingInformation": {
"locales": {
"en-US": {
"summary": "This is a sample Alexa skill.",
"examplePhrases": [
"Alexa, open sample skill.",
"Alexa, turn on kitchen lights.",
"Alexa, blink kitchen lights."
],
"keywords": [
"Smart Home",
"Lights",
"Smart Devices"
],
"name": "Sample custom skill name.",
"description": "This skill has basic and advanced smart devices control features."
}
},
"isAvailableWorldwide": false,
"testingInstructions": "1) Say 'Alexa, discover my devices' 2) Say 'Alexa, turn on sample lights'",
"category": "SMART_HOME",
"distributionCountries": [
"US",
"GB"
]
},
"apis": {
"custom": {
"endpoint": {
"uri": <some-aws-lambda-endpoint-uri>"
}
}
},
"manifestVersion": "1.0",
"privacyAndCompliance": {
"allowsPurchases": false,
"locales": {
"en-US": {
"termsOfUseUrl": "http://www.termsofuse.sampleskill.com",
"privacyPolicyUrl": "http://www.myprivacypolicy.sampleskill.com"
}
},
"isExportCompliant": true,
"isChildDirected": false,
"usesPersonalInfo": false
}
}
}和这些标题字段:
{
"Authorization":"<my-auth-token-that-i-get-from-lwa>"
}预期的响应应采用以下格式:
{
"skill_id": "{skill_id}"
}然而,这是我得到的回应:
{
"message": "User has not consented to this operation"
}(尽管有问题的用户已经同意了这些操作,这在这个权限请求数组中是很明显的:
['profile profile:user_id alexa::ask:skills:readwrite alexa::ask:skills:test alexa::ask:models:readwrite alexa::ask:skills:test alexa::ask:models:read alexa::ask:skills:read'])
此外,如果我以这种方式向Authorization标头添加Bearer前缀:
{
"Authorization":"Bearer <my-lwa-auth-token>"
}我得到的回应是:
{
"message": "Token is invalid/expired"
}考虑到身份验证令牌是在10分钟(也许15分钟)前生成的,并且它仍然在其保质期(大约一个小时)内,这是相当令人惊讶的。
在另一个帖子here中,我头读到亚马逊正在解决这个问题(那是2017年10月21日)。同时,如果你想出了另一种方法,你能描述一下并帮助一个人吗?
发布于 2020-11-16 21:57:08
从Node访问SMAPI的最简单方法是使用SMAPI SDK SDK,带有可用的文档here。
为了使用SMAPI进行身份验证,您需要执行以下操作:
时,使用此刷新令牌使用询问命令行界面来交换您的LWA客户端ID和客户端机密,以换取LWA刷新令牌
const Alexa = require('ask-smapi-sdk');
// specify the refreshTokenConfig with clientId, clientSecret and refreshToken generated in the previous step
const refreshTokenConfig = {
clientId,
clientSecret,
refreshToken
}
const smapiClient = new Alexa.StandardSmapiClientBuilder()
.withRefreshTokenConfig(refreshTokenConfig)
.client();然后,您将能够通过SDK上的函数调用来访问SMAPI!
https://stackoverflow.com/questions/47389444
复制相似问题