简体   繁体   English

如何将无效参数修复为

[英]How to fix Invalid Parameter To

I'm trying to validate codes sent using Twilio. 我正在尝试验证使用Twilio发送的代码。 Currently the function to send the verification code works great, but the function to verify the code is not working as expected. 当前,发送验证码的功能很好用,但是验证码的功能无法正常工作。

I've tried replace the parameter to with To , verificationSid , VerificationSid and none of them seem to work as expected. 我试着更换参数toToverificationSidVerificationSid和他们都不如预期工作。

exports.validateVerificationCode = functions.https.onRequest((req, res) => {
  var number = req.body.number;
  var code = req.body.code;
  twilio.verify.services('VA{MY_SERVICE_ID}').verificationChecks.create({
    to: number, 
    code: code
  }).then((validation_check) => {
    res.status(200).json(validation_check);
  }).catch((err) => {
    res.status(500).json(err);
    console.log(err);
  });
});

I expect the function to run as shown in the API docs, but my firebase console keeps showing me 我希望该功能能够按API文档中所示运行,但是我的Firebase控制台一直向我显示

"[Error: Invalid parameter: To] status: 400" and when I replace 'to' with 'To', it gives me the following error "[Error: Either a 'To' number or 'VerificationSid' must be specified] status: 400". “ [[错误:无效的参数:收件人]状态:400”,当我用“收件人”替换“收件人”时,出现以下错误“ [错误:必须指定收件人”或“ VerificationSid”]状态:400“。

Couple of things, did you check to see if the to number: is in E.164 format, https://www.twilio.com/docs/glossary/what-e164 and that you are using a more current version of the Twilio Node SDK Helper Library? 几件事情,您是否检查过收件人号码:是否为E.164格式, https ://www.twilio.com/docs/glossary/what-e164,并且您使用的是Twilio的最新版本节点SDK帮助程序库? https://github.com/twilio/twilio-node/blob/master/CHANGES.md . https://github.com/twilio/twilio-node/blob/master/CHANGES.md

My working code look very similar, so I feel it is one of the two issues above (I tested with Twilio Node Helper Library 3.31.1). 我的工作代码看起来非常相似,因此我认为它是上面两个问题之一(我使用Twilio Node Helper Library 3.31.1进行了测试)。

exports.handler = function(context, event, callback) {

const client = context.getTwilioClient();   
const code = event.code;
let phoneNumber = event.phoneNumber;

client.verify.services('VA1exxxxxxbc6e02520c585xxxxxxxxxx')
         .verificationChecks
         .create({to: phoneNumber, code: code})
         .then(verification_check => {
             console.log(`***VERIFICATION STATUS***: ${verification_check.status}`);
            //  Object.keys(verification_check).forEach(thisKey => console.log(`${thisKey}: ${verification_check[thisKey]}`));
             callback(null, `${verification_check.status}`);
         })
          .catch(err => {
              console.log(err);
              callback();
          });
         };

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM