javascript - Twilio 响应对象未定义但没有错误?

标签 javascript meteor twilio

我正在致力于在基本的 meteor 应用程序中实现 Twilio。我已经设置了客户端代码来调用下面的服务器端方法(在本例中是在登录时)。

调用该方法时不会出现问题,并且服务器日志中不会产生任何错误。但是,如果我注销我的响应数据,它是未定义的。这是时间问题吗?我的印象是,当收到响应时,会调用包含响应或错误的函数。

如有任何意见,我们将不胜感激,提前致谢!

Meteor.methods({
twilioTest:function () {

console.log("Twilio Test Called!");

    ACCOUNT_SID = "xxxxxxxxxxxxxxxxxxxxxxxxxxx";
    AUTH_TOKEN = "xxxxxxxxxxxxxxxxxxxxxxxxxxx";

    twilio = Twilio(ACCOUNT_SID, AUTH_TOKEN);
    twilio.sendSms({
        to:'+xxx-xxx-xxxx', // Any number Twilio can deliver to
        from: '+xxx-xxx-xxxx', // A number you bought from Twilio and can use for outbound communication
        body: 'Greetings!' // body of the SMS message
    },function(err, responseData) { //this function is executed when a response is received from Twilio
        console.log(responseData); // log out response object
        if (!err) { // "err" is an error received during the request, if any
            // "responseData" is a JavaScript object containing data received from Twilio.
            // A sample response from sending an SMS message is here (click "JSON" to see how the data appears in JavaScript):
            // http://www.twilio.com/docs/api/rest/sending-sms#example-1
            console.log(responseData.from); // outputs outbound number
            console.log(responseData.body); // outputs message body
        }
    });

}

最佳答案

正如 John Hascall 指出的那样,我应该注销错误对象而不是 response object 。这表明我的目标电话号码无效,并允许我纠正问题。

关于javascript - Twilio 响应对象未定义但没有错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34602149/

相关文章:

javascript - 根据三个标记的坐标制作圆圈

javascript - 当订阅已经限制了数据集时,是否有必要将限制传递给数据?

python - 使用 Iron.io 安排 Twilio 通话

python - Twilio/Django 未收到回复短信

twilio - 使用 Twilio 进行调用时是否可以传递自定义参数?

javascript - 替换文本区域的单词

javascript - 如何在javascript中从多个属性中过滤数组的JSON对象

facebook - 如何向 Meteor.users 集合添加附加字段(不在 Profile 字段内)

javascript 给出意想不到的结果

google-maps - 将 Google Places 自动完成与 Meteor 结合使用