如何获取Alexa设备的时区或本地时间 [英] How to get the time zone or local time of Alexa device

查看:158
本文介绍了如何获取Alexa设备的时区或本地时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想获取在

  const apiAccessToken = this.event.context.System.apiAccessToken; 
const deviceId = this.event.context.System.device.deviceId;
let countryCode =‘’;
let postalCode =‘’;

axios.get(`https://api.amazonalexa.com/v1/devices/$ {deviceId} / settings / address / countryAndPostalCode`,{
标头:{'Authorization' :`Bearer $ {apiAccessToken}`}
})
.then((response)=> {
countryCode = response.data.countryCode;
postalCode = response.data .postalCode;
const tz = ziptz.lookup(postalCode);
const currDate = new moment();
const userDatetime = currDate.tz(tz).format('YYYY-MM- DD HH:mm');
console.log('Local Timezone Date / Time :::::::',userDatetime);
})


I want to get the "time zone" set in the settings or local date time of the Alexa device. Is there any API available for it? Or is there any option to get the date-time of the user using his postal code?

Any help will be highly appreciable?

解决方案

Yes, there is a native Alexa API that you can use. Here is a perfect solution for what you're looking for. What you will need is a device ID and an API access token. Also, few tools like

            const apiAccessToken = this.event.context.System.apiAccessToken;
            const deviceId = this.event.context.System.device.deviceId;
            let countryCode = '';
            let postalCode = '';

            axios.get(`https://api.amazonalexa.com/v1/devices/${deviceId}/settings/address/countryAndPostalCode`, {
              headers: { 'Authorization': `Bearer ${apiAccessToken}` }
            })
            .then((response) => {
                countryCode = response.data.countryCode;
                postalCode = response.data.postalCode;
                const tz = ziptz.lookup( postalCode );
                const currDate = new moment();
                const userDatetime = currDate.tz(tz).format('YYYY-MM-DD HH:mm');
                console.log('Local Timezone Date/Time::::::: ', userDatetime);
            })

这篇关于如何获取Alexa设备的时区或本地时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆