如何解决Twilio函数检索语音邮件TypeError:不建议使用参数auth使用`username` /`password`代替
我试图从Get Recording使用示例,但收到错误消息:“ TypeError:不推荐使用参数auth
。请改用username
/ password
。”
我如何更改以下代码以使其工作。
这是我的代码:
const got = require('got');
//Boilerplate for function code
exports.handler = function(context,event,callback) {
// Make an HTTP Request using a template literal for the Twilio API call
//https://api.twilio.com/2010-04-01/Accounts/${context.ACCOUNT_SID}/Recordings.json
got('https://api.twilio.com/2010-04-01/Accounts/${context.ACCOUNT_SID}/Recordings.json',{
method:'get',auth: '${context.ACCOUNT_SID}:${context.AUTH_TOKEN}'
})
.then(res => {
console.log(res);
callback(null,res.body);
})
.catch(err => {
console.log(err);
callback(err);
});
};
解决方法
const got = require('got');
//Boilerplate for function code
exports.handler = function(context,event,callback) {
// Make an HTTP Request using a template literal for the Twilio API call
//https://api.twilio.com/2010-04-01/Accounts/${context.ACCOUNT_SID}/Recordings.json
got(`https://api.twilio.com/2010-04-01/Accounts/${context.ACCOUNT_SID}/Recordings.json`,{
method:'get',username: context.ACCOUNT_SID,password: context.AUTH_TOKEN
})
.then(res => {
console.log(res);
callback(null,res.body);
})
.catch(err => {
console.log(err);
callback(err);
});
};
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。