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

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.

Related

Get list of events user is attending on Facebook

I'm trying to get list of events my friend / user attends. This info is publicly visible through Facebook pages.
I'm making a request to /userid/events but it returns empty array of results, though user does have upcoming events and calling /me/events is working. (all is ran in graph explorer)
I couldn't find any documentation about any limitations or required permissions to explain why it's not working e.g. this link
Is it a bug? How to workaround it?
You can use /userid/events with a user who auzhorized your App, but using /me/events is recommended. Either way, just because stuff is public on facebook.com does not mean you can get it with the API. You always need to authorize users before you can get any data, for privacy reasons.
In other words: It´s not a bug, there is no workaround, it´s not possible without user authorization.

Is it possible to get all user id's who have shared a specific post, through graph api or any other resource?

I am looking for a way to record user id's of a public post for a brand. If there are any resources available, any help would be appreciated.
Retrieving share data with FB API doesn't seem to be officialy supported by Facebook, but you can retrieve posts shares with Graph API, just do the following:
Get the ID of your post (eg. /me/posts query)
Split the ID on underscore character and get the second part (first part indentifies posts author)
Query the shares: [id_2nd_part]/sharedposts
Note that since it's not officialy supported it may stop working at some point in the future
You can test it with Graph explorer - to get shared posts you need read_stream permissions on your access token if I'm not mistaken

Facebook mutual_friend_count wrong?

I would like to know if anyone else has experienced this problem...
Facebook's count of mutual friends is off by 1. One too much. But not for all friends. I've tested this through my app where the fetched mutual_friend_count does not correspond to the number of mutual friends in the fetched array.
Further I have been checking this manually. By going to a FB-profile and literally counted our mutual friends. This also shows that we have one less mutual friend than the number Facebook is displaying in the "Mutual Friends" section on a friend's profile.
This does not apply for all my contacts on Facebook. Some profiles are displaying the number of mutual friends corresponding to the actual number of mutual friends.
But this do posses a problem if you are building an application/wesite/facebook app etc. that somewhat relies on the mutual_friend_count.
Can anyone confirm this? Is this a bug?
Or is it some kind of setting that some users can avoid being shown in the mutual friend section, but is still counted...?
I've been doing some work with mutual_friendsand I figured I'd give my 2-cents on what I've learned on this issue, which may or may not correspond to whats not working on yours.
Documentation for mutual_friends via Facebook Graph API is here
From the docs:
The user in the request and the session user must both have granted user_friends permission to the app.
This is a common mistake I was making. Even if you have mutual friends between users, if the friend has not given permission to the app, then you can't get their picture/name or any info on them, they simply appear in the total_count parameter.
If you want to call this endpoint on behalf two app-users who are not friends, then you must provide the appsecret_proof parameter along with the user access token when making the request. This means you must call this endpoint from your server.
This is also very important. If the two users aren't friends, then this endpoint will silently fail you providing NOTHING even though they have mutual friends. In order to actually get the data for this scenario, you need to be calling the endpoint from your server, not your client. That means not your javascript webapp, not your android app and not your iOS app.
There are some additional edge cases, such as users not providing the mutual_friends permission to your app, among other issues but at least for me these were the main issues I ran into. I never had any off-by-one errors, so I can't confirm your bug.
I can confirm that the mutual friend count is reduced by 1 sometimes. I counted a few, and some are right, and others are 1 less then it should be. It could be a setting in the privacy tab, I'm sorry I'm not much help.

How to search for friends around me using Facebook API?

Using GraphAPI, I see you can request location of a specific friend, or search for friends by criteria.
However, I couldn't find a way to search for friends in my area. I want to perform a search and get a results of friends who are in a radius of X meters from me.
I know I can fetch each friend manually and check its location, but it seems a bit inefficient so I'm looking for a batch search,
EDIT: I've found a similar question (and answer) using FQL: facebook fql query similar to friends checkins
Well, you partly answered yourself there...
When you query about a user friend, you get his location as well since it's part of the User object (assuming you have the right permissions of course): http://developers.facebook.com/docs/reference/api/user/
The problem, as you wrote, is that you'll need to send a request to facebook per friend, which is not the right way to go about this.
Thankfully, facebook already thought of that and they came up with the "Batch Requests": http://developers.facebook.com/docs/reference/api/batch/ which let you do exactly that.
EDIT
Now that I think of it, it's simpler than I wrote before, you don't even need the batch requests since you can get all of the user friends in one request to: me/friends.
Assuming you have the user granted you the needed permissions each user object in the friends list will have the location object as well.
For each friend calculate if his location is in the desired radius.
Also, you can retrieve friends location and hometown using this Graph API endpoint: /me/friends?fields=location,hometown,name
But you will need the friends_location and friends_hometown permissions.
Read more: https://developers.facebook.com/docs/reference/login/extended-profile-properties/

Get all posts on a friend's wall

I'm trying to find an API call (or set of calls) that will allow an app to get the posts that one would see if viewing a friend's wall. Either a REST call or a FQL call would do.
I tried /feed and /posts, compare the results with what I see on my friend's wall, and the results I get from it are incomplete.
I know this is possible because apps like Friendly are able to do it.
Any hints?
Well, there's two different API endpoints for querying the posts of a given user; home and feed. Home includes posts from other people and pages (basically what you see when you log in and go to your home page) and feed is the stuff the user is sharing. Assuming your application has authenticated the user and they've allowed the read_stream permission, you can then make queries to the Graph API using their access token:
https://graph.facebook.com/{SOME_USER_NAME}/home?access_token={SOME_ACCESS_TOKEN}
and
https://graph.facebook.com/{SOME_USER_NAME}/feed?access_token={SOME_ACCESS_TOKEN}
The only hint I could give you is that "incomplete" is pretty standard with the Facebook API. You can only do the best you can with what they give you. Counts will be wrong. Data will be wrong. It's a fluctuating, moving target, so code to that fact.
You can interact with posts by retrieving the read_stream and publish_stream for a given User's ID.
Once you have the ID of the User that you are interested in you can use FQL to retrieve posts from streams that you have the permissions for.
This stackoverflow answer goes into more detail and contains further links to the documentation on the Facebook Developers site.
We do it like this:
1) we use Facebook Platform PHP5 client
2) then what you do is:
$this->facebook = new facebook($key, $secret);
$out = $this->facebook->api_client->call_method("facebook.stream.get", array('viewer_id'=>0, 'source_ids'=>$uid, 'limit'=>$limit));
then just operate with out, which contains all posts on asked page.
but, afaik, it will work only with pages, not with normal users. but dig that way to get answer.
You should make a graph call to https://graph.facebook.com/< FBID >/statuses?access_token=xxxxx
Here access_token shall have read_stream permission and offline_access permission ..