我試圖用ntwitter在膩子終端上顯示一些推文。在根目錄中安裝了節點模塊(express和ntwitter)後,當我嘗試從根目錄運行tweet_counter.js時出現此錯誤。我該如何解決「不能調用方法」流的未定義「
[email protected]:~/app/Twitter$ node tweet_counter
/home/vagrant/app/Twitter/tweet_counter.js:7
twitter.stream(
^
TypeError: Cannot call method 'stream' of undefined
at Object.<anonymous> (/home/vagrant/app/Twitter/tweet_counter.js:7:9)
at Module._compile (module.js:456:26)
at Object.Module._extensions..js (module.js:474:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Function.Module.runMain (module.js:497:10)
at startup (node.js:119:16)
at node.js:906:3
//tweet_counter.js代碼
var ntwitter = require("ntwitter"),
credentials = require("./credentials.json"),
twitter;
// set up our twitter object
twitter = ntwitter(credentials);
// set up our twitter stream with three parameters,
// separated by commas
twitter.stream(
// the first parameter is a string
"statuses/filter",
// second parameter, an object containing an array
{ "track": ["awesome", "cool", "rad", "gnarly", "groovy"] },
// the third parameter is our callback for when the stream is created
function(stream) {
stream.on("data", function(tweet) {
console.log(tweet.text);
});
}
);
不應該'twitter = ntwitter(證書);'是'twitter = new twitter(憑證);'而不是? – Andreas
不起作用,仍吐出相同的錯誤。謝謝! –