I want to design a news feed with fully functioning likes/Unlike ,share and commenting,and of course fetching recent posts from users newfeed.Now here is the thing,I want to check whether a user has liked a post (type is video, photo, link or status).
If a user has liked the post already, then show unlike button, if a user has not liked, show like button.
FILES:
index.php click to open the file
Now there are few problems here: 1- problem is that when ever i run this code,it shows only one post from newsfeed.but if i remove the following code from the code,it will fetch 20 posts from newsfeed .i dont know whats happening.
$ret = $facebook->api(array(
'method' => 'fql.query',
'query' => "SELECT like_info FROM $type WHERE object_id=$object_id"
));
$checklike = $ret['data']['like_info']['user_likes'];
2-we can use object_id only for photos,albums,and videos.but you cant use it to get like_info fro link and status types.so i need new way and a new technique to findout wether user has liked an post or not
3-whenever i add a new $facebook->api() inside the foreach loop,it will fetch 1-3 posts from fb or even not all.
so if you could find anyway to make a news feed with fully functioning likes/Unlike ,share and commenting,and of course fetching recent posts from users newfeed OR fixing the problems i mentioned ,That would be greatful.
please help me as soon as possible,if you need anything ,just comment and i will provide you with.
Thanks.
data
is an array, edit your code to-
$checklike = $ret['data'][0]['like_info']['user_likes'];
or loop around each object, if you are expecting more than one result like:
foreach($ret['data'] as $data)
echo $checklike = $data['like_info']['user_likes'];
UPDATE
The latest version of Graph API today is v2.8. In this version you can get the reactions also. It is better to use reactions than likes as reactions also includes the Love, WOW and HAHA etc reactions which likes does not.
You can add the field for reactions's summary instead of likes's summary as below
fields=reactions.limit(0).summary(true)
Using this you will get the reactions summary as below
"reactions": {
"data": [
],
"summary": {
"total_count": 6,
"viewer_reaction": "LOVE"
}
}, ......
Notice the "viewer_reaction": "LOVE"
which means you have given a reaction to the post which is LOVE. It's value could be any one of LIKE, LOVE, HAHA, WOW, SAD, ANGRY, NONE
. The NONE
means you have not liked the post.