我正在致力于在基本的 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/