如何解决“无法调用未定义的方法'流'

时间:2015-07-28 09:51:07

标签: javascript node.js twitter express vagrant

我正在尝试使用ntwitter在putty终端上显示一些推文。在根目录中安装了节点模块(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);
        });
    }
);

1 个答案:

答案 0 :(得分:0)

对不起,我能够从同一个程序中获取流,请你确保你已经正确安装了ntwitter,确保从项目根目录安装,不需要将其设置为全局,如果需要只保存作为package.json中的依赖..

您可以在cmd上看到我的输出:

G'

@ CampAmerica69听起来像是一个很酷的阵营从来没有去过夏令营哈哈:)     RT @YankydoodlDandy:我喜欢的Villians是Doom博士,Red Skull,Joker(显然),Kang(这么棒的villian)和Riddler ......     真棒! https://t.co/EDrQjEiO7I     RT @obviouslyitsjoy:rad:     rad的定义是一个优秀的人或事物的俚语。     GO VATCH @ BethanyMota的新视频!!!真棒!!!!我很喜欢这些!!这是一个可爱的主意! Ily Beth !!! :) http://t.co/MNkKxTIh28     Jaguar Land Rover通过@engadget #awesome #ilovescience #cars直接在挡风玻璃http://t.co/8cX7pdQtRu上投射数据     RT @bea_ker:&#34;唐 - 这是一个很酷的名字&#34;

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

相关问题