How to get the number of "likes" by your friends for a given place - facebook-fql

Given a place, like https://graph.facebook.com/112088822180423, how can I get the number of likes just by my friends? The graph gives me Likes, Checkins and Talking_About_count, but I just want whose likes by my friends. Is that possible?

If you want to do this for a page you administer and you want do this as an admin, it may not be possible with current API. From https://stackoverflow.com/a/6737579/121052, you cannot get the list of likes for a location or a page. If you had the list, you can fetch a list of your own friends, and then performed an intersection.
However, if it is a feature you are building in an App to be used by it's users - i.e you want to display the list of friends of the user who has liked a page, then that is possible. For that, do the following:
Use http://developers.facebook.com/docs/reference/api/user/#likes to get if the user likes a page/location.
Use http://graph.facebook.com/USER/friends?access_token=XXX to get the list of his friends.
For any friend, you can perform the like check again and make the intersection.
I am sure there might be a way to optimize this operation. Batch Requests will definitely help.

I discovered that this is possible through the use of FQL and the page_fan table

Related

Facebook Graph API: get sum of likes made to friends

Is there a way to get a list of the sums of likes/shares the calling user has made on his/her friends' objects over a specified time frame broken out by friend, without having to iterate over all objects that a user's friends have posted, tallying their likes from that user, and then re-doing that for all of the user's friends?
No, this is not possible with the current Graph API.

How to retrieve the IDs of Facebook pages (places) located in a specific location and liked by a user's friends?

I know one solution would be to retrieve the IDs of places located in a specific location using the Facebook Graph API, to retrieve the IDs of all the Facebook pages liked by my friends and then to pick only the IDs of pages in the location that my friends liked (using the "social context" that enables me to know how many friends liked a page). But it doesn't sound like the best solution to me (it represents LOTS of data).
Another solution could be to imply dependencies between operations in the request using the JSONPath expression format (https://developers.facebook.com/docs/graph-api/making-multiple-requests/) but as said in the documentation "for security reasons filter and script JSONPath constructs are not allowed in the JSONPath expression", which limits significantly the usefulness of this strategy.
So I tried to use Batch Requests:
curl \
-F 'access_token=...' \
-F 'batch=[{"method":"GET", "name":"likes-ids", "relative_url":"me/friends?fields=likes{id}"}, {"method":"GET", "relative_url":"search?type=place&center=48.85,2.35&distance=1000&ids={result=likes-ids:$.data.*.likes.data.*.id}"}]'
There are 2 issues in each batch request:
Weirdly enough, "me/friends?fields=likes{id}" gets me some likes of
some of my friends (I think it's possible to get all the likes of
all my friends as friends_likes has been deprecated, correct me if
I'm wrong)
Even for the user's friends' likes I manage to
retrieve, I don't get anything from the second batch request.
NB: The user's friends shouldn't need to login on my app (meaning I don't have the user_likes permission for them).
I'd be grateful if anyone could help with some remarks or ideas.
You need the friend to grant the user_likes. You are probably using the Graph API Explorer so your friends might have been testing and granted the user_likes permission (thus why you see some and not all)
A user access token with user_likes permission is required to see all pages liked by that person.
https://developers.facebook.com/docs/graph-api/reference/v2.2/user/likes
Notice it doesn't say friends.
For the second part, are you sure the ids returned from the first part of the batch have ids for places? For each friend object, only 25 likes are returned, you aren't guaranteed that the likes you get are pages of type place.
Also search?type=place&center=48.85,2.35&distance=1000&ids=, I don't this does what you think it's supposed to do. ids seems to override the type,center and distance.
e.g. search?type=place&center=48.85,2.35&distance=1000&ids=375093055847509
is the same as
search?ids=375093055847509
Seems like a bug here or an intended behaviour that as along as ids is returned override every other parameter.
So overall no, this batch call will work, the results you are returning are incorrect for your desired outcome.
So the only way is indeed the initial plan you had but in any event the query will only work for friends who are using your app.
https://developers.facebook.com/docs/graph-api/reference/v2.2/page.context/friends_who_like
Only friends who use the requesting app will be returned.

How to track the users have became fans of my facebook page?

I know there is a Facebook tool named insights, but, at the moment it does not give me the information I need.
I would like to create custom invitation code to track how many friend of a specific user have became the fans of my page.
Small example...
John becames fan of my page, I would like to undersand how many friends of John became fans of my page.
I do not know how to do that, but I must need to know how many users have become fans and by whom.
Is this possible with a Facebook page, or do I need to create an application?
Thank you!
This can be done with FQL (Facebook Query Language) using the Facebook Graph API. What you're looking for is the likes attribute which can be obtained from the JSON returned by http://graph.facebook.com/yourusername.
Ofcourse you will need to do further queries to obtain things like how many friends of a specific user liked your page. Probably something along the lines of SELECT ... FROM like WHERE object_id = yourpage and I would imagine you'd need to link that to the friend table with something like WHERE uid1 = friendid to get their friends.

Determine first 50 likes via Facebook Graph API

Is it possible to get for example the first 50 people who liked a post, photo, whatever I created on facebook via the Graph API? Is there any kind of order when accessing connections like /likes or /comments?
Use the following link (given that you have permissions to access to the post):
/likes?limit=50
This should be the first 50 likes ordered via Facebook (usually based on time).
ASFAIK, you cannot get a list of people who like a page. It's a privacy issue. If you wanted to create an app, and users authorized your app, then you could get a list of the current users friends who like the page.

How to get facebook friends list with hometown using Graph API?

I know you can get friends list using this url:
https://graph.facebook.com/me/friends?access_token=XXX
But what I see there is a list of friends with ids and names, but I need hometown on this list. I requested friends_hometown permission, and when I run this url:
https://graph.facebook.com/100001986459077?access_token=XXX
then it works ok - I see hometown among all the fields.
But I don't want to call second URL for all the friends (too many times). I would like to get it in one call using first URL. Is there a way to achieve this target?
Notice: I'm not interested in FQL solution as I know it. All I need is graph API valid url to perform this action.
https://graph.facebook.com/me/friends?fields=id,name,hometown,location&access_token=[access_token_here] will provide you with the list you're wanting.
You will need to ensure the scope for the access token includes the friend's location and hometown in order to retrieve the data for that user's friend data.