Home Counting Facebook comments for *multiple* URLs (Facebook JS SDK) returns 0
Reply: 0

Counting Facebook comments for *multiple* URLs (Facebook JS SDK) returns 0

Alexander Wigmore
1#
Alexander Wigmore Published in 2017-12-05 14:34:43Z

I'm trying to build a blog system which integrates Facebook SDK for the comments—it's all fine apart from showing the count of comments in the blog list.

HTML:

<h1>Getting count of Facebook comments on example.com</h1>
<span class="comment"><fb:comments-count href="https://example.com"></fb:comments-count></span>

JS:

window.fbAsyncInit = function() {
  FB.init({
    appId            : '123',
    autoLogAppEvents : true,
    xfbml            : true,
    version          : 'v2.11'
  });
};

(function(d, s, id){
  var js, fjs = d.getElementsByTagName(s)[0];
  if (d.getElementById(id)) {return;}
  js = d.createElement(s); js.id = id;
  js.src = "https://connect.facebook.net/en_US/sdk.js";
  fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));

Returns: 28


The issue is returning the count of comments for multiple URLs.

Getting the comment count for one URL is easy and works here:

https://jsfiddle.net/mrwigster/1w3ecujq/

However as soon as I try to add another URL to get the comment count for it just returns 0 as the count for all:

https://jsfiddle.net/mrwigster/8wx58qua/

To make it even stranger, if I remove the appId from the JS FB SDK api it works, but then that would break the rest of the system:

https://jsfiddle.net/mrwigster/zztcvv3o/

Am I doing something wrong, I've tried reading the FB developer documentation for this, but it simply provides the one line of code.

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.335852 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO