Is there a way to return only attachments that contain photos from an FQL stream query? - facebook-fql

I am trying to get all the photos that my app has posted to a user's stream using FQL. I realize I could do this by first performing the following query:
SELECT attachment FROM stream WHERE source_id = me() AND app_id = <my_app_id>
and then parsing the attachments locally to determine their type. But I'm wondering, is there any way to include the attachment type in my query so that only attachments with photos are returned?

Facebook has updated the stream table to include "type":
https://developers.facebook.com/docs/reference/fql/stream/
The type of this story. Possible values are:
11 - Group created
12 - Event created
46 - Status update
56 - Post on wall from another user
66 - Note created
80 - Link posted
128 - Video posted
247 - Photos posted
237 - App story
272 - App story
So the answer to my question becomes:
SELECT attachment FROM stream WHERE source_id = me() AND type = 247 AND app_id = <my_app_id>
By the way, it doesn't seem they retroactively updated the stream table i.e. old posts do not have a "type" value

if you have not selected/created a specific album for photos being posted to a users account, all of them will be in the same album - something like <app_name> Photos.
Taken from facebook blog post 489 :
...We automatically create an album for your app if it does not already
exist. All photos uploaded this way will then be added to this same
album.
From there you could retrieve all photo posts made by your app. I find it very unlikely that a user would upload a photo into your app's specific album (although its possible)
In addition, saving photo_id/album_id in your own database for use in the future is a great idea.

Related

API doesn't return photos of group posts

When querying posts from a group the photos are not returned most of the time even though the posts have photos.
We have a working app that uses those photos and starting from about 24 hours ago we almost don't get any photos.
For example, the following post - 45245752193_10152313354342194
has photos and it's also public, but the api doesn't return the photos:
This is my query:
45245752193_10152313354342194?fields=attachments,full_picture,picture
Full_picture and picture don't exists in the response, and in the attachment I get this:
"description": "This attachment may have been removed or the person who shared it may not have permission to share it with you.",
"title": "Attachment Unavailable",
"type": "unavailable"
I also tried to get the photos in two different ways and it didn't work.
1.Querying {group_id}/feed?fields=attachments,full_picture,picture,object_id,from
I get the same error string as before in the attachment field, picture and full_picture are empty.
2.Using fql with the following query:
SELECT source_id,attachment,post_id, message, like_info,comment_info,created_time, share_count,actor_id FROM stream WHERE source_id in (45245752193) and
Here the attachments field is empty.
According to the developer bug centre this is a valid bug, and Facebook are looking to fix this issue.
https://developers.facebook.com/bugs/752853894779368/

How To Get Status Update Posted By Page - Facebook Graph API

I am creating a desktop application in which I needs to grab post_id of only status updates posted by page itself (no photos, videos and other stories/types.) I'm using type parameter to do this task easily.
https://graph.facebook.com/{username or ID of page}/posts?fields=object_id,type&limit=250&access_token={my access token}
The giving URL returning the list of posts with it's types and post ID
My Page Updated a Status
{
"type": "status",
"id": "493341197400693_627621933972618",
"created_time": "2014-04-05T18:31:58+0000"
},
It's working fine but problem is some post in the list with the type=status are not a status update it's a story i.e "My Page commented on a photo"
My Page commented on a Photo
{
"type": "status",
"id": "493341197400693_626576670743811",
"created_time": "2014-04-03T11:27:22+0000"
},
How to confirm that either it is a status update or a Story if the type of both response will be "Status".
I just want to ignore My Page commented on a photo or My Page Likes a Photo etc, Any Suggestion?
Sorry for my bad English.
you can look for the 'message' field. A status should have a 'message' field associated with it, whereas a story like 'My Page Likes a Photo' should not have a 'message'. Here is some sample php code.
if (array_key_exists("message", $post))
//is a status
Modify you graph call to include message, like so.
https://graph.facebook.com/{username or ID of page}/posts?fields=object_id,type,message&limit=250&access_token={my access token}
Have a look at the stream FQL table. You can use the field type to filter the posts to a finer level than it's possible with the Graph API:
https://developers.facebook.com/docs/reference/fql/stream/#columns
Excerpt from the docs:
The type of this story. Possible values are:
11 - Group created
12 - Event created
46 - Status update
56 - Post on wall from another user
66 - Note created
80 - Link posted
128 -Video posted
247 - Photos posted
237 - App story
257 - Comment created
272 - App story
285 - Checkin to a place
308 - Post in Group

How to filter user's news feed to posts/actions from a specific app in Graph API

I have a Facebook app and I want to filter user's news feed to get latest posts/actions that was posted using my app, in Graph API.
I've found this: How to get activity from my app with Facebook Graph API?
This one is okay for getting actions/posts by a specific friend (or the user itself), what I need is almost the same, with the difference that I need this "stream" by all friends of the user that use my app, not a single user.
Then I've found this: Facebook graph api : how to filter app feeds. For this one, the example in the question itself returns empty data for me (with the appropriate access token with read_stream permission). The only answer suggests to use FQL. I've tried SELECT post_id, message, comments, likes FROM stream WHERE app_id = MY_APP_ID and I got this error:
{
"error": {
"message": "Your statement is not indexable. The WHERE clause must contain an
indexable column. Such columns are marked with * in the tables linked from
http://developers.facebook.com/docs/reference/fql ",
"type": "NoIndexFunctionException",
"code": 604
}
}
How do I retrieve the list of all the last (say 100) posts from a specific app by the user and their friends, from the user's scope?
With all FQL queries, your WHERE clause must include at least one indexable field (those are marked with a star next to the field name in the docs) – for performance reasons.
So for the stream table you have a choice between source_id (id of the user whose wall the post is on) or filter_key. You can read the valid filter keys from the stream_filter table – but every user has the filter key nf for what shows up in their news feed. (post_id is also indexable, but of no use for us here.)
So you could try filtering with WHERE filter_key = 'nf' AND app_id = 'YOUR_APP_ID' – that should give you the posts that your active user is able to see in their feed that where made via your app.
You could also try with source_id, filtering that to either being equal to me() (your current user in FQL), or it being in the list of your friends (whose ids you can get from the friend table, again using me(), as a sub-query) - so like this,
… WHERE (source_id = me() OR source_id IN (SELECT uid1 FROM friend WHERE uid2 = me())) AND app_id = 'YOUR_APP_ID'
– but I think that will have less good performance, so I’d try with filter key first and see if that gets you the posts you want.
EDIT: So, as the questioner found out, using /me/home?filter=app_MY_APP_ID works apparently better, and is also easier. Whoever else might need this, they should use this version, since it is more reliable – FQL often gives less results then one would expect.

How can I get all my posts to other people, not to my timeline?

How can i get, using Facebook Graph Api, all my posts to other people, not to my timeline?
I'm trying to use me/posts , but i get all my posts including to my timeline, and i couldn't separate it
Using Facebook FQL API:
SELECT post_id, created_time, description, description_tags, app_id,
message, type, created_time FROM stream WHERE source_id=me() AND
comment_info.can_comment!='' AND actor_id=me() AND permalink="" AND
created_time<=now() LIMIT 150
The only problem is this query doesn't return "Upload photo on friends wall"'s post, because of this unresolved bug at https://developers.facebook.com/bugs/148353975327544. However, this FQL query should works perfectly. Kindly let me know if you're figure out something wrong with this query.
Also, please make sure your user access token have granted "read_stream" permission.
comment_info.can_comment!='' used to exclude "Comment on friend's Status" story feed.
permalink="" used to exclude "Lim and 林果皞 are now friends." or "People changed his profile picture.", "林果皞 created an event."...etc. You can test what would happen if remove this.
Update for comment below:
I think what you can do is extract the id from description_tags which was no start with "0", for example my screenshot, id "100003013144869":
Also, extract the created_time, for example "1368624514"
Then, do a query with:
SELECT post_id FROM stream WHERE source_id='100003013144869' AND
actor_id=me() AND created_time=1368624514
I'm know it's not absolutely accurate(If 2 feed have the same created_time on seconds), however most likely you can make your job done.

How do I retrieve photos from a Facebook group using the GraphAPI?

I would like to retrieve photos from a facebook group using the GraphAPI. Based on FB Docs I don't see any connections to photos. I would like to get the photos and the users who uploaded them.
Graph API:
http://graph.facebook.com/GROUP_ID/?fields=name,description,albums
return
{
"name": "Group name",
"description": "Group description",
"id": "GROUP_ID",
"albums": {
"data": [
{
"id": "GROUP_ALBUM_ID",
"name": "GROUP_ALBUM_NAME",
"link": "GROUP_ALBUM_LINK",
"created": 1352388257,
"modified": 1352388257,
"cover_pid": 444427468954616,
"count": 22
}
],
"paging": {
"next": "https://graph.facebook.com/GROUP_ID/albums?limit=25&offset=25"
}
}
}
and next query
http://graph.facebook.com/GROUP_ALBUM_ID/photos?fields=picture,source,name&type=uploaded
Ive been digging a bit in the same issue.
We have a group album which is has this url
https://www.facebook.com/media/set/?set=oa.10150651435446985
So the ID seems to be oa.10150651435446985
Another empty album gets album gets the set-id oa.10150652583791985
A note in the same group id 10150652589396985
Notice the similarity in ID's.
The direct link: http://facebook.com/10150651435446985 works to go to the album.
The album is created by user 1128233556 and the groupid is 184760601984.
Other, individual (not in an album) group photos are in "set" o.184760601984 where the digit represents the group id.
So what does "o" and "oa" stand for? a=album, o=?
Pictures have the following URL: https://fbcdn-sphotos-a.akamaihd.net/hphotos-ak-ash4/s720x720/420015_3293876662264_1128233556_33234982_110700674_n.jpg
420015_3293876662264_1128233556_33234982_110700674
??????_PHOTOID_______USER_______????_____?????????
Who can make something out of al that?
I have the same problem / here is my partial answer, which remains kind of hack :
one can retrieve photos posted on a group via the FQL group.stream or the GraphAPI group.feed (playing around with the facebook graphApi explorer or the fql query/multiquery test console).
This way you can retrieve all needed information, included a valid id to retrieve the photo, and one to retrieve the object from the graph.
BUT, this is only valid for individual photos.
since my previous answer was deleted, i won't repost it here, but remind that my similar problem is detailed in this thread FQL or GraphAPI unable to retrieve PHOTO ALBUM or VIDEO posted on a GROUP , which, if ever solved, might even as well help people for this very problem here.
Thomas
I don't think Albums in groups R treated like albums on Profile pages. The pics have aid ="0" Even if they are part of albums.
I used The Image below:
https://www.facebook.com/photo.php?fbid=10151350034089218 is the link to the image. And you can guess where I got the object_ID.
In this example 10151350034089218 is the object_ID for an image in an album for my group "T_Group" The link to the group is https://www.facebook.com/groups/217697621700825/.
You can then run the FQL query
SELECT aid
FROM photo
WHERE object_id = 10151350034089218
you'll get
aid
====
0
Even though it is part of an album "Hugh Laurie".
I tried the same FQL query with images in albums on my profile and they always returned an aid with some Number other than 0.
I plan on posting to Facebook bugs, I hope I get a fix. Unless its running as intended.
I tried:
SELECT pid
FROM photo_tag
WHERE subject =217697621700825
...and I got PIDs to photos posted to the group page not images in albums.
I wish I had found a more direct method, but this appears to have promise:
get /me/groups or /me?fields=groups to get the groups ids.
From that, get {group_id}/feed?type=photo This returns just the photos from the feed, but all you really get (toward this goal) is the photo's id (returned as object_id).
Then for each photo you can get /{object_id} which returns all the links to the various sizes of the image.
I did this research in Facebook Graph Explorer, so keep that in mind as you try to implement it.
Rob