希望你们可以帮助我解决问题。所以我一直在为我的Fitbit编码,我尝试对车库门应用进行编程。我可以成功登录帐户,并使用本地提取API(通常使用Vue和Axios)获得该帐户下的设备。 当我用Axios编写一个put请求时,它可以成功通过,但是我无法使其与本机访存api一起使用。
async function closeGarage(){
try {
//THIS WORKS
axios({
method: 'put',
url: 'https://myqexternal.myqdevice.com/api/v4/deviceattribute/putdeviceattribute',
headers: {
MyQApplicationId: appID,
SecurityToken: SecurityTokenData
},
data: {
MyQDeviceId: garageId,
AttributeName: 'desireddoorstate',
AttributeValue: 1
}
}).then(res=>{
console.log(res)
})
//THIS DOESNT WORK
const url3 = `https://myqexternal.myqdevice.com/api/v4/deviceattribute/putdeviceattribute`;
const data3 = {
MyQDeviceId: garageId,
AttributeName: "desireddoorstate",
AttributeValue: 0
}
const response = await fetch(url3, {
method: 'PUT', // or 'PUT'
body: data3, // data can be `string` or {object}!
headers: {
MyQApplicationId: appID,
SecurityToken: SecurityTokenData,
}
});
const json = await response.json();
console.log(response)
console.log('Success:', JSON.stringify(json));
} catch (error) {
console.error('Error:', error);
}
}