Question

I need to know whether user has already liked or not the link in Facebook. I am doing this thing for the first time and have to do it in short span of time so asking directly this question, I tried googling it but didn't get the satisfaction. Reply would be much appreciated. Thanks

Was it helpful?

Solution 2

I got the answer of my question at my own which is as below:

To check whether you have liked any url or not in Facebook first of all you need to get all the urls which you have liked in Facebook. To get the json data for the Liked urls I have called FB Graph api with following code :

NSString *url = [NSString stringWithFormat:@"https://graph.facebook.com/%@/og.likes?access_token=%@&limit=1000",fbUserID,fbUserToken];

You need to pass the user id for the user for which you want liked urls and their access token for the Facebook's current session.

This api call will return the json for the liked urls. Do parse this json, you will get 'url' field from it. Store all this urls in one array.

Now search for the url for which you want to check whether it is liked one or not in this array.

That's it.. it has tackled out my problem.. hope it may help others too..

OTHER TIPS

To check whether user liked a post we need to get data form stream table instead of like table, please follow the below request

Request : 
NSURL *requestURL = [NSURL URLWithString:@"https://graph.facebook.com/fql"];

NSMutableDictionary * params1 = 
[NSMutableDictionary dictionaryWithObjectsAndKeys:
[NSString stringWithFormat:
@"SELECT likes FROM stream WHERE post_id = '%@'",
postID],@"q",facebookOfflineAccessToken,@"accessToken",nil];

In Response we will get Total count of likes and user_likes fileds

Response :
"user_likes" = 0 //for not liked,     
"user_likes" = 1 //for like                                                                                     
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top