Question

I am writing a program to get all the facebook posts on my wall. And from those posts I want to get the names of all the users who have liked or commented on a particular post. I am able to get this using Facebook Graph Explorer using the query as /me?fields=posts (although, it gives me the name of only 25 people who liked my post). But when I do this using code, it gives me things the like pages I liked and albums that I liked and not my wall posts. I have added all the permissions needed.

Here is the code:

<html>
<head></head>
<body>
<div id="fb-root"></div>
<script>
  window.fbAsyncInit = function() {
  FB.init({
    appId      : 'XXXXXXXXXXXXXX',
    status     : true, // check login status
    cookie     : true, // enable cookies to allow the server to access the session
    xfbml      : true  // parse XFBML
  });

  FB.getLoginStatus(function(response){
    if (response.status === 'connected') {
      console.log(response.authResponse.accessToken);
      testAPI();
    } else {
      FB.login();
    }
  },{scope:'email,user_likes,read_stream,user_status,status_update,share_item,video_upload,user_friends,create_node,photo_upload,publish_stream,publish_actions,export_stream,publish_checkins,share_item,video_upload'});
  };

  // Load the SDK asynchronously
  (function(d){
   var js, id = 'facebook-jssdk', ref = d.getElementsByTagName('script')[0];
   if (d.getElementById(id)) {return;}
   js = d.createElement('script'); js.id = id; js.async = true;
   js.src = "//connect.facebook.net/en_US/all.js";
   ref.parentNode.insertBefore(js, ref);
  }(document));

  function testAPI() {
    console.log('Welcome! Fetching your information.... ');
    FB.api("/me?fields=posts", function(response) {
          if (response && !response.error) {
            console.log(response);
          }
          else {
            console.log("Something's wrong");
          }
    });
  }
</script>

<fb:login-button show-faces="true" size="xlarge" width="200" max-rows="1"></fb:login-button>
</body>
</html>

I also tried tried it using FQL using the query SELECT post_id, likes, actor_id, target_id, message,comments FROM stream WHERE source_id = me(). This gives the number of users who liked on the post but gives me no information about the users who liked my post. Please help.

Was it helpful?

Solution

Please check below link:-

How to get picture of user who has commented on my facebook post?

POST_ID?fields=likes.fields(pic_square,name),comments

This might be helpful for you.

OTHER TIPS

If you just want your status updates, you can use the

GET /me/statuses 

endpoint. If you want more filtering on the posts, please refer to the type field of the stream FQL table: https://developers.facebook.com/docs/reference/fql/stream/#columns You can use these in a IN list in your FQL.

You can get infos about the Users who likes your posts like this:

GET /me/statuses?fields=id,message,likes.fields(id,name,pic_square).limit(100),comments.fields(from.fields(id,name,pic_square)).limit(100)&limit=100

if you add likes.fields(id,name,pic_square) where the fields list can be any field of the User. Unfortunately, this doesn't work the same way with the comments, see the output of the above query. You can add limits to each field containing arrays to receive a larger number of results.

For the comments, I guess you only have the options to grab them manually and "joining" them to the results from the Graph API via the user_id (id from the Graph API query equals the uid from the FQL query).

select uid, name, pic_square from user where uid in (SELECT comments.comment_list.fromid FROM stream WHERE source_id = me() and type in (46, 80, 128, 247) limit 100)
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top