如何解决“Cannot call method 'stream'”undefined"

How do I resolve "Cannot call method 'stream' of undefined"

本文关键字:stream quot undefined method call 何解决 解决 Cannot      更新时间:2023-09-26

我正在尝试使用ntwitter在putty终端上显示一些tweet。在根目录中安装了节点模块(express和ntwitter),当我尝试从根目录运行tweet_counter.js时,我得到了这个错误。

vagrant@precise32:~/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);
        });
    }
);

我很抱歉,我能够从您的相同程序中获取流,请确保您已正确安装了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听起来像一个很酷的夏令营,我从来没有参加过夏令营,哈哈:)@YankydoodlDandy:我喜欢的反派有末日博士、红骷髅、小丑(显然是)、康(这么棒的反派)和谜语人……太棒了!https://t.co/EDrQjEiO7I@obviouslyitsjoy: rad:rad的定义是俚语,指优秀的人或事。去看@BethanyMota的新视频吧!!这是太棒了! !我喜欢这些!!这真是个可爱的主意!!y贝丝! !): http://t.co/MNkKxTIh28捷豹路虎直接在挡风玻璃上投射驾驶数据http://t.co/8cX7pdQtRu通过@engadget #awesome #ilovescience #carsRT @bea_ker:"Don -这个名字真酷"

[紧张地出汗]是的,谢谢哈哈