Is there a way to know if a user has liked an object on facebook? - facebook

Is there a way to know if a user has liked an object on facebook, given that the user has given my app permission and I have the correct access tokens ??

it seems to me that it is what are you asking for ...
https://developers.facebook.com/docs/reference/fql/like/

For people who come across this page and want a more specific answer, I use the following FQL query via the js sdk in order to find out if a specific user has liked a specific object. If they have, it will return an array with their id. If they haven't, it will return an empty array:
FB.api({
method: 'fql.query',
query: 'select user_id from like where user_id=' + UserIDVar + ' and object_id=' + ActionIDVar,
return_ssl_resources: 1
}, function(response){
console.log(response);
});

Related

Getting list of friends with koala and fb api

Im trying to return the friend list with uid of an authenticated user. however I only get a partial return value, some part of the friends are just left out:
graph = Koala::Facebook::API.new(fb_token)
friends = graph.get_connections("me", "friends")
#some friend action
when I type in the
friends.paging["next"]
in the browser it also returns an empty json array
"data": [ ]
How am I doing it wrong and what is the correct practice?
You need to get the permission 'user_friends' to get friendlist, otherwise you'll receive a empty data:
The field 'friends' is only accessible on the User object after the user grants the 'user_friends' permission.
Try yourself:
https://developers.facebook.com/tools/explorer?method=GET&path=me%2Ffriends&version=v2.5
So, with correct permission you can do:
graph = Koala::Facebook::API.new(fb_token)
result = graph.get_connections('me', 'friends')
to paginate:
next_page = result.next_page
LAST BUT NOT LEAST:
Only friends who installed this app are returned in API v2.0 and
higher. total_count in summary represents the total number of friends,
including those who haven't installed the app.Learn More
You just try this..
This is very simple to you can get all friend count in a single line :)
#graph = Koala::Facebook::API.new(facebook_token)
#friends = #graph.get_connection("me", "friends",api_version:"v2.0").raw_response["summary"]["total_count"]

Can't get facebook checkins, data array always empty

I have a strange behavior when trying to get the checkins of a place or user: the result is always an empty data array:
{
"data": [
]
}
This happens when I use the Graph Explorer: /4/checkins
or when I use FQL: SELECT checkin_id, author_uid, page_id, timestamp from checkin where page_id = 111856692159256
or when using javascript:
FB.api("/me/checkins", function(response){
console.log(response);
});
I always use an access_token, even ones with ALL permissions available. Simply no result.
I read, that checkins are now post with locations, so I tried /4/posts?with=location, but still no luck. Is there some kind of bug, or restriction (country/app-permissions) I am missing?
EDIT: I now got lucky and can get of SOME of my friends their checkins. It's like a 50/50 chance...
There are 2 differences commands, one command is the url to get the user checkins:
/me/checkins will return all checkins of the current user (the user that generate the token)
/<USERID>/checkins will return all checking from the User ID that the current user can see.
/<PLACEID>/checkins will return all friends of the current user that made checkin at this place
So, probably you have no friends that made checkins at the id 111856692159256

Facebook: identify object id and type by url

I want to get the id and type of a Facebook object based on its URL.
My goal is to identify if a certain URL is a Facebook Event (for example https://www.facebook.com/events/258629027581347).
So if I had the object-id of that object I could do the following FQL query and know that if I get a result the object is an Event:
select eid from event where eid = 258629027581347
The problem is getting the object-id based only on the URL. I do not want to parse the id from the URL because there is no guarantee that the format of the URL will remain the same in the future. I want to find a way to do it through one of Facebook's API's.
After searching for a while, I found the following suggestions for how to do this, but unfortunately none of them work:
FQL query from the object_url table - the query yields no results:
SELECT url, id, type, site FROM object_url WHERE url = "https://www.facebook.com/events/258629027581347"
Use the graph api:
https://graph.facebook.com/https://www.facebook.com/events/258629027581347
This returns a JSON object containing only the URL - no id.
Use the graph api with ?ids= like this:
https://graph.facebook.com/?ids=https://www.facebook.com/events/258629027581347
This returns the following JSON, also no id:
{
"https://www.facebook.com/events/258629027581347": {
"id": "https://www.facebook.com/events/258629027581347",
"metadata": {
"connections": {
"comments": "https://graph.facebook.com/https://www.facebook.com/events/258629027581347/comments?access_token=AAACEdEose0cBADzSuuyJWohIwkXuvQGJUsIlSJz04J4nzKqqQXTvGiPXf4YDBPuh0rdyXgSWnWcJpN3X3GaATVLjG6UmZBiHKmcxCWwZDZD"
},
"type": "link_stat"
}
}
}
What am I missing here?
Thanks!
To my knowledge, there isn't an API method at this time that takes a Facebook URL and tells you what it is. The only way to go about this is to parse the URL and look for the last element and pass this to https://graph.facebook.com/258629027581347?metadata=1&access_token=XXXX
It's a noble goal that you are trying to build a future-proof Facebook application, but I don't think that is a possibility at this time. The Facebook platform is still evolving. There is less of a guarantee that the api methods will remain constant than the url struture.

comment.create event gives me an useless comment id because I cannot make a query with it [duplicate]

I am using Facebook comment box plugin:
<fb:comments href="${myPageUrl}" num_posts="20" width="630"></fb:comments>
Every thing is working fine. The problem is that I want to store the comment posted into my database. Is there any way to fetch the text posted on the comment box.
I am using the following js to catch comment-create event.
FB.Event.subscribe('comment.create', function(response) {
alert(response.commentID)
});
I'm getting some commentId from this but I don't know how to fetch the exact comment posted on a particular comment-create event.
Coomie: Actually whenever a comment is posted, I catch the event thru 'comment.create'. I was able to catch the event but I was wondering how to get the comment(text) posted at that particular event. Like event.text or event.comment but there was no direct method found
So, now I am manipulating it with fql. Which is somewhat similar to you example. First retrieving the whole list and then selecting the top one.
My sample code is below:
FB.Event.subscribe('comment.create', function(response) {
FB.api({
method: 'fql.query',
query: "SELECT post_fbid, fromid, object_id, text, time from comment WHERE object_id in (select comments_fbid from link_stat where url ='${PageUrl}') order by time desc limit 1"
},
function(response) {
var feed = response[0];
alert(feed.text)
});
});
So this method is giving me exactly the same result I want.
I don't have the complete answer but this should get you on your way.
You can use the facebook graph api to extract information about an open graph id (an open graph id is FB's way of identifying a person, website, application or URL). Eg. this page:
http://www.inhousegroup.com.au/newsroom/23-best-practice-for-advanced-seo/ (the place that fired me)
uses a comment box. The web page has an open id of 10150441190653416. So when you comment on this page facebook sees your comment as a wall post on that page's "wall".
Using the graph api, you can get some JSON info about the page here:
http:/graph.facebook.com/10150441190653416
And you can get the posts from this address:
http://graph.facebook.com/10150441190653416/posts
But you'll have to get an access token.
Then you just have to import the posts on save and compare your db to the JSON and add records as neccessary.
Good luck!
FB.Event.subscribe('comment.create', function(response) {
var commentQuery = FB.Data.query('SELECT fromid, text FROM comment WHERE post_fbid=\'' + response.commentID + '\' AND object_id IN (SELECT comments_fbid FROM link_stat WHERE url=\'' + response.href + '\')');
FB.Data.waitOn([commentQuery], function () {
text = commentQuery.value[0].text;
// Use your preferred way to inform the server to save comment
$.post( 'http://example.com/comment', text )
});
});

Facebook GetMutualFriends Method failing for no clear reason

I've an application that runs on a webpage, it has a list of facebook id's and run through them checking if the logged user has any mutual friends with the id's on the list; for making this verificaton I'm using the Rest API with the friends.getMutualFriends metond, I'm using this method becasue in this way I can get the mutual friends without having both users authenticated, I just need the authentication for the origin userid, in the case of FQL or using the Graph API both users should be connected so that I can get the mutual friends, this is why the getMutualFriends method is so useful in this case. The problem that I'm having is that when I try to pull the mutual friends for a user that has a lot of friends then I get this error
"error_code": 18,
"error_msg": "This API call could not be completed due to resource limits",
if I try to do that with a user that has less frineds the in will work, I know that saying less or a lot is novet very accurate , so , lets take a look at this example, if I try to execute this call with a user that has 300 friends the call will work, but if I try to do that exact same thing with a user that has 700 friends it'll return back with the error that I put above, so I thought that it could be the amount of calls per second so I limited that but it did not worked, I tried resetting the app keys, I've tried with several differente users, I've tried to do it with a new application, and even if I just try make one call to compare 2 users it'll fail if the user has a large amout of friends, the code that I'm using for this is
function getMutualFriends($facebook, $uid1, $uid2)
{
try
{
$param = array(
'method' => 'friends.getMutualFriends',
'source_uid' => $uid1,
'target_uid' => $uid2,
'callback'=> ''
);
$mutualFriends = $facebook->api($param);
return $mutualFriends;
}
catch(Exception $o)
{
return serialize($o);
}
return null;
}
function getMutualFriendInfo($facebook, $uid1, $uid2)
{
$mutualfriends=getMutualFriends($facebook, $uid1, $uid2);
if (is_array($mutualfriends))//!=''))
{
$friend_uids = implode(",",$mutualfriends);
try
{
$param = array(
'method' => 'users.getInfo',
'uids' => $friend_uids,
'fields' => 'name,pic_square,pic_big',
'callback' => ''
);
$friend_info = $facebook->api($param);
return $friend_info;
}
catch (Exception $o)
{
return serialize($o);
}
}
return serialize($mutualfriends);
}
So my questions are, is there anything that I'm doing wrong on this cade so that it fails? Is there any othere way to do this besides the friends.GetMutualFriends method? I've already tried with this SELECT uid1 FROM friend WHERE uid2=[targetID] AND uid1 IN (SELECT uid2 FROM friend WHERE uid1=[sourceID]) but it did not worked. Is there any specific origin on this error?
I'm very confused because it works for some users and it doesn't for others, I've searched if there's any api limit but I've not found anything on that, there are no errors on the API dashboard, this code seemed to work before, and if I execute the call on the test console on facebook I'll get the same error,
Thanks for are your help, any idea will be appreciated.
There's a bug reported in facebook.
http://bugs.developers.facebook.net/show_bug.cgi?id=15644
firstly you should migrate from old rest api to new graph api.... because facebook will obsolete the old rest api soon.
secondly try this query
SELECT uid1 FROM friend WHERE uid2='your user id'
I hope that it will work