我試圖發送短信(在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的崩潰。 –