I'm implementing a skill for Amazon Alexa.I want to determine the user's geolocation, but the http.get request is not working. I tried the request in postman and I get the desired result, but couldn't figure out what could be the problem. The request url should be like this https://api.amazonalexa.com/v1/devices/{deviceId}/settings/address
with the Authorization header Authorization: Bearer {token}
.
Here is my code
try{
var body = "";
console.log('Authorization ', consentToken);
var response = '';
var options = {
host: 'api.eu.amazonalexa.com',
path: '/v1/devices/'+deviceId+'/settings/address',
port: '443',
headers: {'Authorization': "Bearer "+consentToken},
method: 'GET'
};
https.get(options, function(res) {
console.log('status', res.statusCode);
if (res.statusCode >= 200 && res.statusCode < 400) {
res.on('data', function(data_) { response += data_.toString(); });
res.on('end', function() {
var data = JSON.parse(response);
console.log('data', data);
if (data.length > 0)
userLocation = data;
});
}
}).on('error', function(e) {
console.log("errrrror",e);
}).on('uncaughtException', function (err) {
console.log('uncaughtException',err);
});
}
catch(error) {
console.log('getAndProcessUserLocation',error);
}
I don't know why the https.get is not executed. No error is thrown, but I couldn't get any log from it.
via Coder
No comments:
Post a Comment