Which user's data can I access through fql? - facebook-fql

Okay, total noob question:
I want to understand what FQL can do, so I know if it can be useful to me before I try to learn it. From browsing Facebook's documentation I could not understand the following:
With FQL, can I search among ALL registered users for e.g. users of a certain age and gender from a certain region? Or can I only search among my friends?
Please provide a quote from and a link to official or otherwise reliable documentation along with your "yes" or "no".
Thank you!

The Facebook API only returns things that are visible to the owner of the access_token when making a query. FQL has the added requirement that the first field in your WHERE portion of the query must be indexable. These are marked with a ★ in the documentation.
For your example of querying the user table, your query must have one of the following immediately after WHERE: uid IN, username IN, name IN or third_party_id IN. The easiest way to get a list of these is by passing a subquery to get the current user's friends via WHERE uid IN (SELECT uid2 FROM friend WHERE uid1=me()). There are some other, more complex ways to get at a list of ids.
As for your app, it's going to be very hard to search for this reliably. The user's age, gender and location are up to the user to populate. The user can choose not to populate these, or keep them private. If these items are private, keep in mind that this filtering takes place after your query completes, so it is possible that all results returned by your query will be filtered out.

Related

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.

Can you make a user-based search with Facebook API?

On Facebook when you write something in the search box in the top.
Like 'Eric'
You first get the results with your friends named Eric and further down you get people you might know with X mutual friends and some random people in the vicinity you might know.
Is it possible to make a similar search with the Facebook API?
I've tried:
https://graph.facebook.com/search?q=eric&type=user&fields=id,name&access_token= (my token)
And thought if I added my access_token I would get a search like the one on Facebook. But I just get some random Eric's from all over the world.
I'm writing a simple web application and getting this search to work would be great! Thanks!
It's possible to an extent but before looking further ensure this isn't the main service of your app otherwise you run the risk of violating Facebook policy on replicating core functionality.
You need to look into the user FQL table and the friend table
Do an FQL call as follow:
SELECT name FROM user WHERE uid IN (SELECT uid2 FROM friend WHERE uid1=me())
Then save the JSON response from that call and use a typeahead algorithm / plugin.

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

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

Facebook FQL Query for `is_minor` field -- special permission required?

I'm using a FQL query to access the Facebook User table and I'm trying to access the is_minor column.
I know I'm submitting the FQL query properly, because all the other information I'm requesting in the query, including Birthday, is being properly returned. However, the response for is_minor is always blank. I've tested this with several users who I know for certain are minors (under 18 years old), but the field is still blank in my FQL response.
Is there a special permission that is needed in order to access this column in the FQL table?? Any one know why I'm not seeing any data for this field in the FQL response?
(I want to access this field because I want to prevent my app from processing certain actions with Users, or Friends of Users, who are minors. In many cases the User or Friend may not have made their Birthday available through the API, so I may not be able to calculate their age myself. I just want to know if they're 18 or older.)

get a list of people using my facebook application

I want to get a list of all users (even if they are my friends or not) who are using my facebook application. Is this possible? If so, how?
And another quick question if we're still here :) Assue I have a facebook id of a person, can I retrieve his name by using it?
I don't believe that you can get a list of all the Facebook IDs of users of a particular application. There doesn't appear to be a possible query for this based on an examination of the FQL tables, probably due to performance and privacy reasons. Generally the presumption is that you maintain a local list of users in your own application, and correlate them to Facebook via their ID, so you would already have all these IDs.
To answer your second question though, yes, that is definitely possible. The Facebook API provides both the users.getStandardInfo and the users.getInfo methods, both of which take user Ids and return information about the user, including the name. users.getInfo can even be used without a session key to just get the name of the user.