[英]API Key in NodeJS for Alexa Lambda
如何使用API密鑰和HTTPS:請求在Node.Js中調用API? 這是我要執行的操作,但無濟於事。 另外,我應該在哪里放置API密鑰? 我還沒放在這里
var options = {
host: 'demo4444447.mockable.io',
port: 80,
method: 'GET',
path: '/alexa-skill.json'
}
var req = http.request(options, res => {
res.setEncoding('utf8');
var returnData = "";
res.on('data', chunk => {
returnData = returnData + chunk;
});
res.on('end', () => {
var result = JSON.parse(returnData);
//callback(result);
this.response.speak(`The current temperature is ${result.temperature} degrees with a humidity of ${result.humidity} and a cloud cover of ${result.cloudcover}.`);
this.emit(':responseReady');
});
});
req.end();
API密鑰通常作為標頭發送。 例:
var options = {
host: 'demo4444447.mockable.io',
port: 80,
method: 'GET',
headers: {'headername': 'headervalue'},
path: '/alexa-skill.json'
}
但是,您需要知道標題名稱,例如“ x-api-key”。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.