How to retrieve user image in FQL selected comments from stream? - facebook

I'm building a simple FQL module to pull in comments from any Facebook fan page.
Getting the post_id, message, actor_id seems pretty straightforward.
However the stream documentation does not seem to indicate any way to get the avatar and name.
What I'm doing is:
SELECT post_id, message, actor_id
FROM stream
WHERE source_id = 125938460770575
Which returns FB Id, comments and the post itself.
I need the user info as well to go along with this.
The obvious solution is to just to an extra FQL API call for every single FB Id (actor_id) that appears to get this info, but I assume there is a better way to do it.
Can I please get some hints on how to do this?

You can use an FQL Multi-Query to achieve that – you “name” your queries, and then the second query can refer to values (in this case the user ids) the first query fetched.
https://developers.facebook.com/docs/technical-guides/fql/#multi has an example that is very similar to what you want, except for that it looks up the user names and pics for users attending an event – but to rewrite that for what you want should be no big deal.
Afterwards you only have to match the ids you get for the users commenting on something with the ids from the second query while processing/displaying the data.

The obvious solution is to just to an extra FQL api call for every single fb id (actor_id) that appears to get this info, but I assume there is a better way to do it.
Yes of course, you can do it like this-
SELECT uid,
pic,
first_name,
last_name
FROM user
WHERE uid IN(
SELECT post_id,
message,
actor_id
FROM stream
WHERE source_id = 125938460770575)
Fetch any detail of the user

Related

Getting 'pic-square' from user posts on the news feed using Facebook Graph API

I'm trying to get the 50 x 50 profile picture for user posts on the news feed. It's easy to do this for likes and comments on posts but I can't figure out how to do it for the initial posts.I also want to limit the query so that I only get results from "people" not "pages" and I only want unique results. In other words if a user appears twice on the feed I only need their picture once. I've played with the Graph API Explorer extensively and have looked all over the forums, here, as well as the documentation on the Facebook developers site. I would think this would be a common request so I'm not sure why it's been so hard to find.My guess is that the syntax of the query would look something like this. Although this query doesn't work in the explorer.
me/home/?fields=from.id.fields(pic_square),from&profile_type=user
Well after a lot of research and trial and error with FQL I figured it out. It's a series of nested queries and it returns an array with the urls of the pic-square images of the users whose posts appear in your news feed. The FQL query looks like this:
SELECT pic_square FROM user WHERE uid IN (SELECT actor_id FROM stream WHERE filter_key IN (SELECT filter_key FROM stream_filter WHERE uid=me()))
I was not able to differentiate between user and page profile pics.

How to display the last post of a facebook page on my webpage

I've got a facebook page which is publicly accessible. On my website I'd like to display the last post made by this page.
I made a script which uses the facebook php-api and FQL to retrieve the events from the page. But I just can't figure out how to construct a FQL which displays the latest posts from my page. I've seen the stream table and thought I should use it like this:
SELECT created_time,
likes, message, post_id, share_count, type
FROM
stream
WHERE
actor_id = {$page}
LIMIT 5
But that results in the fact I need a Starred/Indexable column. Fair enough, but I can't figure out which starred column to use.
Anybody?
You should use: source_id instead of actor_id

How do I pull the name of the user that posts to our page wall?

I have looked through and couldn't find the answer on here...
We are doing a promotional giveaway and have a ton of addresses of people trying to get free stuff. What we want to do is give the people who post most on our facebook wall a better chance of winning.
So I am trying to set something up (I'm guessing using Graphs API/FQL) that will pull the name of the person who posted to our wall or commented on one of our posts. If I can get a list like this, I have enough php/mysql experience that I can create the code to compare the name with the database and weight their entry.
Does anyone have a simple explanation on the code to pull just the names of the people who posted each time?
Thank you so much for your help!!
Using FQL you can get the ids of those who posted on your page wall:
SELECT post_id, actor_id
FROM stream
WHERE source_id = "PAGE_ID"
and those who commented on posts:
SELECT post_id, fromid
FROM comment
WHERE post_id = "POST_ID"
You also should be able to combine them:
SELECT post_id, fromid
FROM comment
WHERE post_id IN (SELECT post_id
FROM stream
WHERE source_id = "PAGE_ID")
Once you have the ids you can simply query: https://graph.facebook.com/USER_ID and get the name of the user.
If you have too many and don't want to issue a request per one you might want to consider using the Batch Requests option.

List of people who shared on facebook

I've been scouring the docs for a while now and can't seem to find a way to accomplish this. The information is available publicly (on a facebook page ... the link says "View all # shares") but I can't seem to find a way to access this info either via FQL or the graph API.
I know I can get a list of likes for a given post:
https://graph.facebook.com/87236249496_134765166623967/likes
The goal is to get a list of people who've shared -- but there doesn't seem to be the same sort of thing for shares. Am I missing something?
You can do it via "graph.facebook.com/OBJECT_ID/sharedposts" connection:
I figure it out this connection via metadata=1 parameter:
Go to... http://www.facebook.com/ajax/shares/view/?target_fbid=10154612868272801&__a=1
10154612868272801 is Facebook story ID, __a stands for asynchronous.
You will see large amount of text/JSON, it is basically HTML & JS for little popup window. There is portion of text like hovercard.php?id=# where # is Facebook user ID, using preg_match_all you then get all of the user ID's who shared that post.
Eg: 100000541151971 (Eric) and 9204448 (Courtney)...
Unfortunately, you must be logged into Facebook to do first step, figure it out :)
I think you can get the share_count from stream table by FQL query just like
SELECT type, source_id, share_count, permalink, description, post_id, actor_id, target_id, message , share_count
FROM stream
WHERE filter_key = 'others' and post_id = '87236249496_134765166623967'
you can test it https://developers.facebook.com/tools/explorer/
Note: you have to take the read_stream permissions as explained here
Tye this link: https://graph.facebook.com/134765166623967/sharedposts (with a valid access_token)
The id in the link is the wallpost id (87236249496_134765166623967) minus the page id (87236249496) and minus the underscore.
You'll also need the read_stream permission
I know you're looking to get at shares through the post_id, but can you settle for finding shares by page_id instead of post_id?
If you can, then you can use the following FQL to get the data you're looking for.
SELECT via_id, created_time, owner_comment
FROM link
WHERE owner = me()
You can then compare via_id against the posts author (page ID) to determine if this share came from the post author in question.
Unfortunately, there seems to be a bug with the data return where some of the via_ids come back as 0. There is a ticket in with Facebook which, at the time of this post, has been open for three weeks at medium priority. I have no idea if this issue is specific to my app or affects everyone, but that query might get you what you want.

Querying stream table for user's own posts returns photo tags by others

I am querying the stream table to retrieve everything that the logged in user has posted recently. I am using the following query:
SELECT source_id, actor_id, app_id, post_id, created_time, message, likes, attachment
FROM stream
WHERE source_id = XXXXX
AND actor_id = XXXXX
The problem is that the response includes entries for when other users have tagged the logged in user in photos, which I don't consider to be a post from the logged in user him/herself.
I have looked at other fields in the stream table such as taget_id and viewer_id but cannot find a way to limit the results.
Can anyone help me to excludes these tag posts or identify in the returned data which entries are tagged photos (or other things that can be tagged)?
Thank you in advance.
// Peter
You can accomplish what you're trying to do by looping over the entries, and if the attachment is a photo or video, checking to see if the owner id is the same as the user id. If it's a different user id, then you know they didn't post it and they were just tagged in the photo.