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

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.

Related

How to get the posts that a friend reshares using FQL?

I faced with the following problem. I would like to know how to get all the posts that has been reshared by my friend using FQL. I use the following query:
SELECT post_id, type, source_id, actor_id, target_id, via_id, app_id FROM stream WHERE source_id=<friend_id> AND via_id LIMIT 0,100
but unfortunately it returns an empty list. At the same time, when I execute the following query for my account I get the list:
SELECT post_id, type, source_id, actor_id, target_id, via_id, app_id FROM stream WHERE source_id=me() AND via_id LIMIT 0,100
I generated a token for all possible permissions. Could someone, please, point me how to solve this problem?
Your both queries are correct.
SELECT post_id, type, source_id, actor_id, target_id, via_id, app_id
FROM stream
WHERE source_id=<friend_id> AND via_id
LIMIT 0,100
It is only that, through the API, you can't access Users from depth 2. For instance, it is impossible to get your friends' friendlist.
If one of your friends shared one of your friend's post, then you will see one result.
If one of your friends shared a random user's post, then no results.
For privacy reasons, the API only allows to access the information in a quite closed circle of friends.
Yeh.. I was wondering about the question as well for some time..
Using Graph API we can get all the links that I have shared..
GET me/links?fields=link
Try this:
SELECT via_id, link_id, caption, url
FROM link
WHERE owner={user_id}
via_id will show you the unique identifier of the original link poster. If via_id=0 you are the original linkposter.
At least it will work for links.

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

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

How to get fb posts of a mentioned page

I'm admin of a Facebook Page and i'm trying to get by API or FQL, contents posted on private streams wall mentioning my page.
If i try
SELECT type,target_id, post_id, message, actor_id, tagged_ids FROM stream WHERE source_id=PAGEID
i will get only: my posts(or page's) on the page wall, posts by a user on the pages wall, but i can't see posts by a user on their own wall that tags the page.
*Every user that visit my page can see them, so they should be accessible* by some API...but i can't understand how.
Thanks
You should be able to get this information by querying the stream_tag table, but in my tests I can't get it to return any data.
If the posts are visible on your page, you should be able to get at the posts mentioning you with this query:
SELECT type, target_id, post_id, message, actor_id, tagged_ids
FROM stream WHERE source_id =PAGEID AND actor_id !=PAGEID

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.

How to query stream table to get updates when some of my friend is tagged in a photo

my project requires get updates from my friend when they are tagged in a photo. On facebook site, such kind 'someone is tagged in a photo' message is automatically categorized in one of my frined list (for example: close friend) other than the news feed category. So I use below FQL to query the stream table:
SELECT post_id, source_id, updated_time, created_time, actor_id, target_id, message, attachment, comments, likes
FROM stream
WHERE filter_key in
(SELECT filter_key FROM stream_filter
WHERE uid = me() AND type = 'friendlist')
AND is_hidden = 0 ORDER BY created_time DESC
But unfortunately, all updates I see on the facebook site exist in the query result except for the photo tag updates.
Does anyone know what's the issue or how can I retrieve such photo tag updates ?
Thanks
Similar question here: How can I get "is now friends with" and "was tagged in" posts in Facebook Graph API?
Unfortunately the answer isn't what you want to hear.