2015-07-28 53 views
0

我試圖用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); 
     }); 
    } 
); 
+0

不應該'twitter = ntwitter(證書);'是'twitter = new twitter(憑證);'而不是? – Andreas

+0

不起作用,仍吐出相同的錯誤。謝謝! –

回答

0

我很抱歉,我能夠從你的相同程序提取數據流,你可以請確保你已經正確安裝ntwitter,請確保您安裝從項目的根目錄,沒必要讓全球性的,如果需要的話只需保存在的package.json依賴..

你可以看到我的CMD輸出:

RT @ToughAmanda: Watch @WWEToughEnough tonight at 8 pm est � Don't forget    to download the app for some cool behind the scenes stuff &amp; votin… 
#ReCap -&gt; #ReReplay #Exciting #Awesome 
RT @DiegoNoJuuzou: #MTVHottest Demi Lovato https://t.co/4tmtAOiV2p 
41 awesome things to do in London this week http://t.co/OxM1QfxTCm 
@cieraira aku dh lama xminum cool blog. Sbb xde hg mungkin. Haha 

@ CampAmerica69聽起來像一個很酷的營地,從來沒有去過夏令營之前,哈哈:) RT @YankydoodlDandy:我愛上的Villians是Doom博士,紅色頭骨,小丑(顯然),康一個真棒villian),和Riddler ... 太棒了! https://t.co/EDrQjEiO7I RT @obviouslyitsjoy:rad: rad的定義對於一個優秀的人或事物來說是俚語。 GO WATCH @ BethanyMota的新視頻!這很棒!!!!我喜歡這些!這是一個很可愛的主意!伊利貝絲! :) http://t.co/MNkKxTIh28 捷豹路虎項目的直接驅動在擋風玻璃上的數據http://t.co/8cX7pdQtRu通過@engadget #awesome #ilovescience #cars RT @bea_ker:「唐 - 這是一個很酷的名字」

[緊張出汗]好的,謝謝,哈哈

相關問題