我试图发送短信(在Twilio的API Explorer中工作),但似乎在我的节点安装下失败。我刚刚完成卸载并重新安装无效。TypeError:无法读取未定义的属性'sid'
错误
7 Oct 21:28:37 - [nodemon] starting `node scraper.js`
Free on Xbox One, Xbox 360, PS3, PS4: Tales from the Borderlands (Episode 1)
/Users/rhysedwards/Downloads/insightful/ozbargain/node_modules/twilio/node_modules/q/q.js:126
throw e;
^
TypeError: Cannot read property 'sid' of undefined
at /Users/rhysedwards/Downloads/insightful/ozbargain/scraper.js:39:31
at /Users/rhysedwards/Downloads/insightful/ozbargain/node_modules/twilio/node_modules/q/q.js:1924:17
at flush (/Users/rhysedwards/Downloads/insightful/ozbargain/node_modules/twilio/node_modules/q/q.js:108:17)
at doNTCallback0 (node.js:408:9)
at process._tickCallback (node.js:337:13)
7 Oct 21:28:39 - [nodemon] app crashed - waiting for file changes before starting...
错误与向后剥离twilio代码;
7 Oct 22:24:44 - [nodemon] starting `node scraper.js`
/Users/rhysedwards/Downloads/insightful/ozbargain/node_modules/twilio/node_modules/q/q.js:126
throw e;
^
TypeError: Cannot read property 'sid' of undefined
at /Users/rhysedwards/Downloads/insightful/ozbargain/scraper.js:12:24
at /Users/rhysedwards/Downloads/insightful/ozbargain/node_modules/twilio/node_modules/q/q.js:1924:17
at flush (/Users/rhysedwards/Downloads/insightful/ozbargain/node_modules/twilio/node_modules/q/q.js:108:17)
at doNTCallback0 (node.js:408:9)
at process._tickCallback (node.js:337:13)
7 Oct 22:24:46 - [nodemon] app crashed - waiting for file changes before starting...
代码
var accountSid = 'AC*******';
var authToken = 'da********';
var fs = require('fs'),
request = require('request'),
cheerio = require('cheerio'),
client = require('twilio')(accountSid, authToken);
url = 'http://www.ozbargain.com.au';
request(url, function(error, response, html) {
if (!error && response.statusCode == 200) {
var $ = cheerio.load(html);
var $el = $("a:contains('Xbox')");
if ($el.length) {
client.messages.create({
to: "61448141065",
from: "+61418739508",
body: "hey",
}, function(err, message) {
console.log(message.sid);
});
console.log($el.text());
} else {
console.log('hey');
}
}
});
对不起,没有解决问题。 Nodemon仍然会崩溃'TypeError:无法读取未定义的属性'sid'。我相信问题必须是节点如何访问Twilio节点模块。 –
@RhysEdwards您是否在代码中的任何其他位置使用过'.sid',如果有的话,也在那里添加类似的代码。另外,检查'message'中是否有响应。 – Tushar
这就是我写的代码源的全部内容(显然依赖于调用的模块)。没有从消息中得到任何答复。假设这是由于TypeError的崩溃。 –