我正在尝试使用Twilio API将短信发送到号码,但出现类似[RestException [Error]: The 'To' number 9977428080 is not a valid phone number.] {
status: 400,
message: "The 'To' number 9977428080 is not a valid phone number.",
code: 21211,
moreInfo: 'https://www.twilio.com/docs/errors/21211',
detail: undefined
}
的错误
在获得the from number is not valid
之前,我将API的凭据测试切换为实时凭据,这是另一个问题。
这些是下面的代码
const client = require('twilio')(config.SId, config.AccesToekn);
// SEND OTP TO USER ACCOUNT
router.post('/sendsms',(req, res, next)=>{
client.messages.create({
from:'+15204770942',
to:"9977428080",
body:'Please user this OPT to verify your number 74536',
}, function(error, data){
if(error){
console.log(error,'error')
console.log(data,"data")
}
})
})
和我的凭证是正确的。 造成此问题的原因可能是什么,我们将不胜感激
预先感谢
答案 0 :(得分:1)
遇到同样的问题。 但是,这里我们只需要添加国家代码。
var message = MessageResource.Create(
body: "Order Placed on BulkyBook. Your Order ID:" + id,
from: new Twilio.Types.PhoneNumber(_twilloOptions.PhoneNumber),
to: new Twilio.Types.PhoneNumber("+91" + orderHeader.PhoneNumber)
);
答案 1 :(得分:0)
error.moreInfo:'https://www.twilio.com/docs/errors/21211'
进一步的格式:
示例:+14155552671
更改为:
const client = require('twilio')(config.SId, config.AccesToekn);
// SEND OTP TO USER ACCOUNT
router.post('/sendsms',(req, res, next)=>{
client.messages.create({
from:'+15204770942',
to:"+9199778080", //this must be a verified phone number for twilio trial accounts
body:'Please user this OPT to verify your number 74536',
}, function(error, data){
if(error){
console.log(error,'error')
console.log(data,"data")
}
})
})
答案 2 :(得分:0)
使用 Twilio 时,请始终使用带有电话号码的国家/地区代码