如何在Node.js中使用getstream.io构建新闻源?

时间:2017-07-02 16:31:23

标签: javascript node.js mongodb express getstream-io

const stream = require('getstream');

//newsfeed stream
const client = stream.connect( null, );

var user1 = client.feed('user', 'user1');

// Add activity; message is a custom field - tip: you can add unlimited custom fields!
user1.addActivity({
  actor: 'user1',
  verb: 'add',
  object: 'picture:10',
  foreign_id: 'picture:10',
  "time": now.toISOString(),
});

// jack's 'timeline' feed follows chris' 'user' feed:
var jack = client.feed('timeline', 'jack');
jack.follow('user', 'user1');

// Read 'timeline' for jack - the post by chris will show up:
jack.get({ limit: 10 }).then(function(results) {
  var activityData = results;

  // Read the next page, using id filtering for optimal performance:
  jack.get({ limit: 10, id_lte: activityData[activityData.length-1].id }).then(function(results) {
    var nextActivityData = results;
  });
});

// Remove activity by referencing foreign_id:
user1.removeActivity({ foreign_id: 'picture:10' });

在这个例子中,我正在使用提供给我的代码来创建一个getstream.io的新闻源。我之前没有做过这样的事情,所以我不知道从哪里开始。

1 个答案:

答案 0 :(得分:0)

我们有一个特定于节点的“Pinterest”示例应用,您可以使用它来开始使用https://github.com/GetStream/Stream-Example-Nodejs

我还建议您查看我们的博客文章,了解制作真正吸引人的新闻Feed的提示,https://getstream.io/blog/13-tips-for-a-highly-engaging-news-feed/