在流星中制作twilio rest api的错误

时间:2016-12-10 20:05:19

标签: meteor twilio

我关注twilio tutorial但是在进行http调用时遇到了问题。我用自己的SID和令牌替换了SID和令牌,但是当我提交呼叫时,我收到以下错误:

  

Error: failed [401] {"code": 20003, "detail": "Your AccountSid or AuthToken was incorrect.", "message": "Authentication Error - No credentials provided", "more_info": "https://www.twilio.com/docs/errors/20003", "status": 401}(…).

我很困惑,因为我提供了正确的凭据。我的代码如下。谢谢!

HTTP.call(
            "POST",
            'https://api.twilio.com/2010-04-01/Accounts/' + 
            'sid' + '/SMS/Messages.json', {
                params: {
                    From: '+14013541756',
                    To: "+14012610096",
                    Body: "yo"
                },
                // Set your credentials as environment variables 
                // so that they are not loaded on the client
                auth:
                    'SID+ ':' +
                    'token'
            },
            // Print error or success to console
            function (error) {
                if (error) {
                    console.log(error);
                }
                else {
                    console.log('SMS sent successfully.');
                }
            }
        );
  }

1 个答案:

答案 0 :(得分:1)

我甚至不会编译:

        auth:
            'SID+ ':' +
            'token'

应该是

            auth:
                SID+ ':' +
                'token'

但是,这可能是一个红色的鲱鱼,你有没有检查你的环境变量是否设置正确,使用console.log(process.env.XXX) - 假设从服务器调用此方法...?