【问题标题】:[RestException [Error]: The 'To' number 9977428080 is not a valid phone number[RestException [错误]:“收件人”号码 9977428080 不是有效的电话号码
【发布时间】:2020-02-23 03:12:34
【问题描述】:

我正在尝试使用 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")
     }
 })
})

我的凭据是正确的。 发生此问题的原因可能是什么,非常感谢您的帮助

提前致谢

【问题讨论】:

    标签: node.js twilio one-time-password


    【解决方案1】:

    error.moreInfo: 'https://www.twilio.com/docs/errors/21211'

    Twilio accepts phone numbers in E164 format: [+] [country code] [subscriber number including area code]

    进一步的格式:

    What is E.164?

    示例:+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")
         }
     })
    })
    

    【讨论】:

    • 感谢您的回复,我已根据我的国家/地区代码(例如 +919568172162)进行了更改,因为我来自印度,但它给了我错误,例如[RestException [Error]: The number is unverified. Trial accounts cannot send messages to unverified numbers; verify at twilio.com/user/account/phone-numbers/verified, or purchase a Twilio number to send messages to unverified numbers.] {
    • 我认为这作为一个新问题会更好,但是,Twilio 不允许您在他们的试用帐户中使用未经验证的电话号码(以避免垃圾邮件并迫使您升级您的帐户等) Here's how to verify phone number
    • 我可以理解它不允许未经验证的号码,但我拥有的一个号码也是经过验证并在我的 tiwilo 帐户中注册的号码。所以它验证了它应该被接受。
    • 对于试用帐户,必须验证两个号码。 +15204770942+19977428080 you need to see both numbers listed here
    • 是的 +9199778080 已列出,但这个不是 +15204770942 显示它是 twilio 编号
    【解决方案2】:

    遇到同样的问题。 但是,这里我们只需要添加国家代码。

                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)
                    );
            
    

    【讨论】:

    • 请对您的回答进行详细的解释,以便下一个用户更好地理解您的回答。
    【解决方案3】:

    使用 Twilio 时,请始终使用国家代码和电话号码

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-04-28
      • 1970-01-01
      • 2017-08-28
      • 2016-11-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多