我试图在一些推特使用双npm软件包和流星。我已经安装了陨石:npm和http作为依赖项,但仍然没有运气。这是我的代码:
/* server/lib/twitter-api.js */
Meteor.startup(function() {
var Twit = Meteor.npmRequire('twit');
Meteor.methods({
'getStream': function() {
var stream = T.stream('statuses/filter', { track: ['football']})
stream.on('tweet', function (tweet) {
console.log(tweet)
})
}
});
});
/* private/twitter.js */
var T = new Twit(config) {
consumer_key: "xxxxxxxx",
consumer_secret: "xxxxxxx",
app_only_auth: true
}
/* client/views/twitter/twitter.js */
Template.tweets.helpers({
'streams': function() {
return Session.get("streams");
}
});
Template.tweets.events({
'streams': function () {
Meteor.call("getStream", function(error, res) {
console.log(res);
Session.set("tweet", res)
});
}
});<template name="tweets">
<h1>Tweets</h1>
{{ streams }}
</template>
很少有问题:( 1)我的twit配置键是否以正确的路径/正确的格式存储?( 2)我的流星方法是否正确地存储?在我收到一个错误,说找不到它之前,现在我的控制台什么也没说,我需要做什么才能完成这个工作?现在,它正试图在推特上贴上“足球”的标签。有更简单的方法吗?我应该只使用http.get而不是双npm包吗?
谢谢!
发布于 2015-08-10 19:26:39
您可以尝试使用twitter包公开我发现的以下两个npm模块:https://atmospherejs.com/danimal/twit只是为了让生活更简单。
另外,您需要记住twit将是异步的,因为它是npm模块。您需要将对twitter的调用转换为同步调用
这就是方法的问题所在,它会在真正得到任何东西之前返回
var stream = T.stream('statuses/filter', { track: ['football']})
我们需要强制它等待流的结果,使用wrapasync或https://github.com/meteorhacks/meteor-async
server/文件夹或更好的settings上。Meteor.startup用于meteor.methods怎么让它起作用?Helper很好,但是最好在客户端调用meteor方法,比如服务器端的+ sync函数:
Template.tweets.onCreated(function() {
Meteor.call("getStreams", function(error, res) {
console.log(res);
Session.set("streams", res)
});
});https://stackoverflow.com/questions/31926294
复制相似问题