【发布时间】:2019-07-24 13:34:08
【问题描述】:
这是我的代码,用于使用 Alexa 技能获取个人资料详细信息,但出现 401 问题以及以下错误
const GetMyEmailIntentHandler = {
canHandle(handlerInput) {
return (
handlerInput.requestEnvelope.request.type === 'IntentRequest' &&
handlerInput.requestEnvelope.request.intent.name === 'GetMyEmailIntent'
);
},
async handle(handlerInput) {
var apiaccessToken = handlerInput.requestEnvelope.context.System.apiAaccessToken;
var options = {
host : baseURL,
path : '/v2/accounts/~current/settings/Profile.email',
Accept: 'application/json',
method : 'GET',
headers:{
auth: 'Bearer ' + apiaccessToken
}
}
// making the https get call
var getReq = https.request(options, function(res) {
res.on('data', function(data) {
});
});
//end the request
getReq.end();
getReq.on('error', function(err){
});
return new Promise(resolve => {
getEmail(apiaccessToken => {
var speechText = 'Your accessToken fetched successfully';
resolve(
handlerInput.responseBuilder
.speak(speechText)
.reprompt(speechText)
.getResponse()
);
});
});
}
};
导致的错误消息是 401 错误,指出无法确定域名。它还说我有一个无效的令牌。但是,我已将身份验证承载令牌作为选项对象内的标头提供。我正在执行字符串连接以将 Bearer 显示为 handlerInput 上的 api 令牌。
2019-07-24T13:12:17.200Z c3b8254b-e773-43db-8a96-0ff0aeea1f5e Error handled: Unable to determine the domain name
2019-07-24T13:12:17.418Z c3b8254b-e773-43db-8a96-0ff0aeea1f5e
status code:============= 401
2019-07-24T13:12:17.419Z c3b8254b-e773-43db-8a96-0ff0aeea1f5e
INSIDE res.on:============= { code: 'ACCESS_DENIED', message: 'Invalid token' }
END RequestId: c3b8254b-e773-43db-8a96-0ff0aeea1f5e
【问题讨论】:
-
标题应该是“授权”而不是“授权”
-
同时将“Accept”移动到 headers 对象中。
标签: node.js async-await alexa-skill