Facebook - get user likes and comments - php

Is it possible to get the user likes and comments from facebook?
With the graph api, you can can do me/likes, but that only returns the pages you liked, and I want all the likes. So also the url's, posts, pictures, ... I liked. The same for the comments.
Or is there a query to get the activity log from an user?

You can use the
FQL like table (https://developers.facebook.com/docs/reference/fql/like/)
FQL comment table (https://developers.facebook.com/docs/reference/fql/comment/)
to query for object comments and likes. Then, if you want to distinguish between object types (photo, album, event, group, note, link, video, application, status, check-in, review, comment, post) for getting more info about the like or comment, you need to do queries like this for each object type:
select src, link from photo where object_id in (select object_id from like where user_id=me() and object_type="photo" limit 25)
For URL likes you can use
FQL url_like table https://developers.facebook.com/docs/reference/fql/url_like/

You can use the Graph API. You have to fetch them with different end-points, like:
Get the posts with: /me/feed - demo
Perms req: read_stream
Get the photos with: /me/photo - demo
Perms req: user_photos
Now, to get the likes use this:
/likes?id={post_id|photo_id|url}
for comments:
/comments?id={post_id|photo_id|url}
You can test your calls in Graph API Explorer

Related

Get a photo with most likes in facebook album

How can i get the photo with the most likes in a facebook album and when i get for a single album how can i count for example for last 7 created albums the picture with the most likes?
There's no option to sort Graph API results as far as I know. So, either you count and sort the results of the Graph API request
GET /{album_id}/photos?fields=album,id,likes
yourself (see https://developers.facebook.com/docs/graph-api/reference/v2.1/album/photos#read), or if you have a Graph API v2.0 app, you can use the following FQL to retrieve the most liked photo of an album:
select object_id, like_info.like_count from photo where album_object_id="{album_id}" order by like_info.like_count desc limit 0, 1
where {album_id} is your actual album_id.
Concerning the 7 last created albums, you'd have to query first for the most recent albums, and then execute the above request for each of them (because FQL doesn't support GROUP BY statements). You can use the Batch API to run these 7 requests in parallel (see https://developers.facebook.com/docs/graph-api/making-multiple-requests).
If you put some effort in the Batch call generation, you could even do the whole 8 requests in one, if you use the referencing feature. Have a look at https://developers.facebook.com/docs/graph-api/making-multiple-requests#operations

Facebook open graph, filtering friends list array

I want my application to filter the friends list I get using the open graph. People who login into my site must see only their friends who also use my app. I've noticed this on many applications like Quora, Thumb etc. How can it be done using php?
Can easily be done when you use FQL to query the user table (in conjunction with the friend table) – that has a field is_app_user, so a query like
SELECT uid, name FROM user
WHERE uid IN (SELECT uid1 FROM friend WHERE uid2 = me())
AND is_app_user
will return only those friends of the current user that are also users of your app.
You can access the lists of a user by access the friendslist connection via graph api
example: http://developers.facebook.com/tools/explorer/?method=GET&path=me%2Ffriendlists
/me/friendlists?access_token='.$access_token.'

Get only photos from users wall feed using facebook graph api

https://graph.facebook.com/me/home?access_token=token
will return all feeds for a user news feed. But i am looking for filters like type=post or type=photos etc
Is this functionality available in facebook api??
You can filter results in home connection of user filtered by user's stream filters by using filter argument. For example photos may be accessed with:
https://graph.facebook.com/me/home?filter=app_2305272732
And Links:
https://graph.facebook.com/me/home?filter=app_2309869772
filter should be one of those returned by next FQL query:
SELECT filter_key FROM stream_filter WHERE uid=me()
See stream_filter table for details.
BTW: Beware, not everything may be possible to use as filters, for example statuses (those easier to access via /me/statuses than via /me/home)...
I couldn't find it documented, but I just tried the following url and it worked:
https://graph.facebook.com/me/home/photos?access_token=token
For anyone looking to do this with fql, I recently wrote a blog post of getting photos and videos from Facebook news feed. And here is the query that I use.
SELECT actor_id, created_time, likes, post_id, attachment FROM stream WHERE filter_key IN ( SELECT filter_key FROM stream_filter WHERE uid = me() AND (name = "Photos" OR name = "Video"))

Facebook API FQL multiquery to get actor name as well as ID

I am making an FQL query using the Facebook PHP API, like so:
$stream = $this->facebook->api('fql', array(
"q" => "SELECT post_id, actor_id, message, description, description_tags, type, attachment
FROM stream
WHERE filter_key in (
SELECT filter_key
FROM stream_filter
WHERE uid=me() AND type='newsfeed'
) AND is_hidden = 0"
));
This gives me the user's news feed. However, this will only provide me with the ID of the actor - I need the actor's name. (By actor, I mean the author of the story in the news feed.)
I understand that I will need to query the API again to retrieve the name. How do I perform such a multiquery? Using this example, how can I get the actor name?
Most people's initial reaction would be to suggest a multi-query. However I dont suggest it for the following reason: It is possible you app can already knows the name of the actor.
Let's say you do lots of these calls to get stream items (one of my production applications does and I've got it coded the way I describe). What you don't want to do is overload the API and make Facebook unhappy with your app id and start reducing your call limits!!
So, what you can do is cache (using memcached, web application cache, database, or other) the user name (as the name to id rarely changes for a give id) based upon the actor_id. This is also valuable to find the to/from ids for other facebook fql objects like comments, likes, etc.

Facebook API: How do you get the url for the last created picture?

How can I get the url of the picture I just uploaded to facebook through the API?
I need the user to make it its profile picture and I want to give him a fast link to go there.
Alright, so using the Graph API you need to do this:
Retrieve a list of of all albums
Determine which album was changed most recently
Retrieve a list of photos in that album
Determine which photo was changed most recently
Here's how you do it:
First you call: https://graph.facebook.com/me/albums
Which gives you a list a list of all the albums, each album has a key called "updated_time". Loop through all the albums and compare them to see which one is the most recent one.
When you have found the most recent one you take the id of that album and call: https://graph.facebook.com/{ the album id }/photos
This will give you a list of all the photos in that album. Each photo has a key called "created_time". Use that to determine which photo is the most recently created. When you have done that you can just take the value in the key "source" which is an url to the full scale of the picture.
If you want a smaller picture there's a key called "images" which contains a list of 4 different sizes; 590x480, 221x180, 130x105 and 92x75. Each of those items in the list has the "source" key.
You can use FQL to do this very fast by issuing the following query:
SELECT object_id FROM photo WHERE aid IN(SELECT aid FROM album WHERE
owner = me() ORDER BY modified DESC LIMIT 1) ORDER BY modified DESC
LIMIT 1
This will return just the graph object id, which you can then simply issue a graph API request to https://graph.facebook.com/object_id
If you want more fields than just the object_id, check these docs: http://developers.facebook.com/docs/reference/fql/photo/

Categories