Search code examples
facebookfacebook-social-plugins

Facebook Social Plugin - How do I retrieve comments embedded in a site?


Problem

I have a unique question that might have not been answered before.

I want to post an image to a Facebook social plugin which I have tried getting a listing of posts from two separate URLs.

First step I have tried to get this to work

I am currently trying to get a list of posts by the desired URL (Unsuccessful URL 2).

I found the following question on StackOverflow and tried adding the URL into the address bar for both websites below.

Programmatically posting Facebook comments

URL 1 works fine, but URL 2 does not.

1) Successful URL Correct JSON Returned

http://graph.facebook.com/comments/?ids=http://techcrunch.com/2011/07/22/big-surprise-the-ipad-trumps-android-tablets-at-the-office/

2) Unsuccessful URL Empty JSON Returned

http://graph.facebook.com/comments/?ids=https://www.change.org/p/set-armeniangenocidedoodle-on-april-24-googledoodles/u/10495296?utm_source=petition_update&utm_medium=facebook&utm_campaign=fb_comment

Empty JSON Response

{
   "https://www.change.org/p/set-armeniangenocidedoodle-on-april-24-googledoodles/u/10495296?utm_source=petition_update": {
      "comments": {
         "data": [

         ]
      }
   }
}

Question

Why can I not get any JSON data for URL 2 ?


Solution

  • Why can I not get any JSON data for URL 2 ?

    Because you passed the wrong URL, by failing to properly URL-encode the parameter value.

    http://graph.facebook.com/comments/?ids=https://www.change.org/p/set-armeniangenocidedoodle-on-april-24-googledoodles/u/10495296?utm_source=petition_update&utm_medium=facebook&utm_campaign=fb_comment

    Let’s take that apart, shall we?

    You pass one parameter ids with the value https://www.change.org/p/set-armeniangenocidedoodle-on-april-24-googledoodles/u/10495296?utm_source=petition_update, and then two more parameters utm_medium with value facebook and utm_campaign with value fb_comment.

    The ampersand separates URL parameters. If you don’t want it to do that, but have it be part of a parameter value instead – then you need to URL-encode it properly.

    http://graph.facebook.com/comments/?ids=https%3A%2F%2Fwww.change.org%2Fp%2Fset-armeniangenocidedoodle-on-april-24-googledoodles%2Fu%2F10495296%3Futm_source%3Dpetition_update%26utm_medium%3Dfacebook%26utm_campaign%3Dfb_comment

    (Not only the ampersand was encoded here, but the whole parameter value. You should do that whenever you put any value into a URL context.)