我目前正在努力将亚马逊Alexa与我们现有的系统集成。我必须做的TL; DR版本是我应该能够通过Alexa技能管理API以编程方式创建Alexa技能。
虽然这非常简单,但我在认证阶段遇到了障碍(涉及使用亚马逊登录):
这应该起作用的方式是,您对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']
)
此外,如果我以Bearer
标头添加Authorization
前缀:
{
"Authorization":"Bearer <my-lwa-auth-token>"
}
我收到了这个回复:
{
"message": "Token is invalid/expired"
}
考虑到auth令牌仅在十分钟(可能十五分钟)之前生成,并且它仍然在其保质期内(大约一小时),这是非常令人惊讶的。
在另一个帖子here中,我读到亚马逊正在研究这个问题(即2017年10月21日)。与此同时,如果你已经制定了另一种方法,你能描述一下并帮助一个人吗?
答案 0 :(得分:0)
从Node命中SMAPI的最简单方法是使用SMAPI Node.js SDK,并提供here文档。
要通过SMAPI进行身份验证,您需要执行以下操作:
ask util generate-lwa-tokens --client-id <Client ID> --client-confirmation <Client Secret>
将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!