如何在 Node.js 中使用 getstream.io 构建新闻提要?
How to build a news feed with getstream.io in Node.js?
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 的新闻源。我以前没有做过这样的事情,所以我不知道从哪里开始。
我们有一个特定于 Node 的 "Pinterest" 示例应用程序,您可以使用它开始,https://github.com/GetStream/Stream-Example-Nodejs
我还建议您查看我们的博客 post,了解制作真正吸引人的新闻提要的技巧,https://getstream.io/blog/13-tips-for-a-highly-engaging-news-feed/
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 的新闻源。我以前没有做过这样的事情,所以我不知道从哪里开始。
我们有一个特定于 Node 的 "Pinterest" 示例应用程序,您可以使用它开始,https://github.com/GetStream/Stream-Example-Nodejs
我还建议您查看我们的博客 post,了解制作真正吸引人的新闻提要的技巧,https://getstream.io/blog/13-tips-for-a-highly-engaging-news-feed/