How to get comment count on livefyre?

旧时模样 提交于 2019-12-04 14:03:46

问题


I would like to get the livefyre comment count in my own database so that I can then sort my articles by comment count.

Every time a page is read on my site, I'd like to ask Livefyre how many comments that certain page has, then update the database with that count.

I tried to get the source of the page but it doesn't seem to be helpful.

Any suggestions?


回答1:


Atish's answer is correct as the best way for the JavaScript on the page to be notified of the Comment Count so that you can track via client-side analytics or update another place on the page where the count is rendered.

From the server side, you can use the 'init' request for any Conversation to retrieve the public comment count.

  • Docs: http://answers.livefyre.com/developers/api-reference/#link-collection-info-plus
  • Example: http://bootstrap.livefyre.com/bs3/livefyre.com/4/NTg0/init (look for numVisible)

Finally, you can use the Livefyre Activity Stream API to get a real-time firehose of your community activity, which you can use to keep a count up to date on your end.

  • Docs: http://answers.livefyre.com/developers/advanced-topics/activity-stream/



回答2:


Check custom implementation of Livefyre comment here

https://github.com/Livefyre/livefyre-docs/wiki

When you call

 fyre.conv.load({"network": self.network,
                                 authDelegate: self.authDelegate
                               }, [ self.config ], self.lfready)

you need to pass call back event in self.lfready i.e.

 app.on('commentCountUpdated', self.onCommentCountUpdated);

This 'commentCountUpdated' is livefyre call back event which returns you the number of comment counts.

 self.lfready = function(app) {
            //Wrap in try catch because Livefyre catches errors in the callback (seemingly)
            //And we want to catch and log ourselves.
            try{
                $.log("Livefyre is ready, attaching custom handlers");
                //Attach events
                app.on('commentCountUpdated', self.onCommentCountUpdated);
                //Only update to zero if the onCommentCount hasn't fired already
                self.$commentContainer.find("#lf_comment_stream").show();
            }catch(err){
                $.error("Livefyre failed to load", err);
                self.$commentContainer.hide();
            }
        };


self.onCommentCountUpdated = function(number){
            console.log("Latest count from LF stream event:" + number)

        };


来源:https://stackoverflow.com/questions/14727481/how-to-get-comment-count-on-livefyre

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!