How to query Graph API page-id/feed so it returns information about if every returned post is liked by access token owner?
One query is requirement.
There is no single API call for this, you would need to go through every like in the result to check if the User ID is in there.
Keep in mind that you would need to use paging in order to get all likes though: https://developers.facebook.com/docs/graph-api/using-graph-api/v2.2#paging
...So that would be a LOT of calls, unfortunately. Depending on the number of likes.
Related
I tried with graph api explorer to get user count. It work perfectly.
But how to get the total post count using API.
Is there any way to get the user count and post count of a a user using userId?
There is no field or endpoint to get a user’s post count.
(Getting the user’s permission to read their posts, and then paginate through all of them & do the count yourself, might sound possible in theory, but in reality that probably won’t work. You’ll run into the API request limits quickly, plus there’s likely always gonna be some posts your app can’t “see” because of some obscure constellation of privacy settings. Also, from my experience, the API tends to get kinda unreliable, the further you try to go back in time.)
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¢er=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¢er=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¢er=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.
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
Using Facebook's Graph API, I am currently looping through all friends to retrieve their videos, and then present a list of these videos to the user. It obviusly takes a while to do this depending on number of friends,
Is there any way to just say to FQL - give me all videos that I have permsission to view?
Facebook doesn't want applications to be able to "mine data". They don't want applications to be able to collect that much data on anything they want. In most cases an ID must be specified.
User ID
Page ID
Group ID
Event ID
etc...
Even in such a case there is also limitations and multiple calls will have to be made. The limitations themselves are not only limited to accessing data with FQL or the Graph API.
There are also limitations on your access to the API. This is called application throttling and it can be enforced on your application if they find you doing an abnormally large amount of calls to the API. There are also other limitations such as making multiple sequential posts or even duplicate posts to your users.
I'm afraid that the answer is no.
Just playing around with the graph API explorer:
http://developers.facebook.com/tools/explorer?method=GET&path=fql%3Fq%3DSELECT%20vid%2C%20owner%2C%20title%2C%20src%20FROM%20video%20WHERE%20owner%3Dme%28%29
I know that to get a list of my friends I can do:
SELECT uid2 FROM friend WHERE uid1=me()
I then updated the video query to:
http://developers.facebook.com/tools/explorer?method=GET&path=fql%3Fq%3DSELECT%20vid%2C%20owner%2C%20title%2C%20src%20FROM%20video%20WHERE%20owner%20IN%20%28SELECT%20uid2%20FROM%20friend%20WHERE%20uid1%3Dme%28%29%29
And now I get a paginated list of all videos belonging to my friends. This one query is certainly better than pounding the API to death with multiple calls. :)
I'm really struggling with something that should be a simple matter: Showing a user of my Facebook app a list of their friends also using the app. Is there nothing built into the APIs to allow such a common request?
The only thing I can think of to do is to get the list of the user's friends, and then get all the users from my database who are in that list, and then fetch information for each of those facebook ids. But that seems an extremely roundabout way of doing things...
The only way I've found to do this is to use FQL and a previously documented, but now undocumented field:
SELECT uid,name FROM user WHERE uid IN (SELECT uid2 FROM friend WHERE uid1=<user's uid>) AND is_app_user=1 ORDER BY name
The undocumented field is the user.is_app_user, which is listed in the old documentation wiki but not in the shiny new docs. No idea if this means it'll be removed in the future, but there doesn't seem to be any other way to get this data with the new Graph API.
Just in-case you're still using the old REST API, you can also call the friends.getAppUsers method.
You can actually use Facebook's old REST API to do this by sending a GET request to: https://api.facebook.com/method/friends.getAppUsers
If you need JSON data back, then add the parameter format=json
You need an access token to do this. See the documentation here:
http://developers.facebook.com/docs/reference/rest/friends.getAppUsers/