Facebook Graph API: How to filter home & feed by application? - facebook

The Facebook Graph API lets you grab a JSON representation of home (News Feed) & feed (Wall).
How do I just get the posts made by my Facebook app?

Facebook has added support to filter me/home posts without using FQL by passing the filter parameter.
For example to get just photos you can do:
me/home?filter=app_2305272732
Full documentation is here: http://developers.facebook.com/docs/reference/api/user/#home

You can now run Facebook Query Language (FQL) queries using the Facebook Graph API (base URL: https://graph.facebook.com).
Let's say your application is Twitter. Twitter's Facebook application ID is 2231777543.
I came up with the FQL queries below with the help of #danontheline's answer and by carefully reading Facebook's documentation on FQL stream & FQL stream_filter.
The following excerpt is particularly pertinent:
If you specify a filter_key from the stream_filter FQL table or
multiple users, results returned will behave like the user's homepage
news feed. If only one user is specified as the source_id, you will
receive the profile view of the user or page. You can filter these
profile view posts by specifying filter_key 'others' (return only
posts that are by someone other than the specified user) or 'owner'
(return only posts made by the specified user). The profile view,
unlike the homepage view, returns older data from our databases. In
the case of a Page, the profile view also includes posts by fans.
Twitter Tweets on Your Facebook News Feed
GET /fql?q=SELECT post_id, actor_id, message, app_id, attribution FROM stream WHERE filter_key = 'app_2231777543'
Twitter Tweets on Your Facebook Wall
GET /fql?q=SELECT post_id, actor_id, message, app_id, attribution FROM stream WHERE source_id = me() AND app_id = '2231777543' LIMIT 1000
Running these queries with the Facebook Graph API Explorer returns Facebook Graph API post objects (The result set will differ depending on access_token, privacy, etc.). You can find out more about each post by adding other columns of the stream table to the queries above and/or by simply making another Graph API request to GET /{post_id} for eache post_id returned by the FQL stream queries above.

Afaik thats not possible with just the Graph API. But you can just use a FQL statement to retrieve the wall/feed, too. With this technique you are able to resrict it to the posts made by one actor_id (which should be your app ID in this case):
SELECT post_id, target_id, message FROM stream WHERE filter_key in (SELECT filter_key FROM stream_filter WHERE uid=me() AND type='newsfeed') AND is_hidden = 0 AND actor_id = 'MattDiPasqualesAppID'
Thing here is that it won't return a JSON, but a XML representation of the result. With phps DOM class you are easily able to convert it into a JSON format or any other representation you want to have of the result!
As you might be handling the whole thing with PHP anyway, you also could just take the json array, parse it into an array and filter the array with keys of your appID.

Related

How do I get all photos from a Facebook post using FQL

When I use the Facebook API with FQL I have this query:
SELECT attachment FROM stream WHERE post_id = 'xxxx'
If the post has more than 9 pictures related to it, I only get data from the first 9.
I have tried setting both limit and filter_key in the query to see if it produces another result, but it does not.

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 to read a user's newsfeed with fql

I'm using the query suggested in Facebook API reference:
"SELECT post_id, actor_id, target_id, message FROM stream WHERE filter_key in (SELECT filter_key FROM stream_filter WHERE uid = me() AND type = 'newsfeed')"
I get most of the items that I see in my "Home" feed on Facebook but not all of them. Any idea why?
Users have the ability to block apps from accessing any of your data, or certain types just certain types of their data. You can set this from the FB front end at Privacy Settings -> Apps, Games & Websites -> How people bring your info to apps they use.
The API filters these items for visibility after your query is executed. There is no way to see what is missing.

How can I get only pictures from the facebook news feed using Graph API?

I'm looking at the Facebook Graph API and trying to pick out any pictures that a user has in their news feed.
I've found that if I use the API /me/feed I can get access to the entire feed. Each entry in the returned data array has a field called "type" which describes what kind of object it is. For example, I've seen the following:
"type": "status"
"type": "photo"
"type": "video"
etc...
Obviously I don't want the status, video or etc types and would like to filter out those results on the server but haven't figured out how. I was hoping it'd be something as simple as adding a query string like ?type=photo but that isn't the case.
Is there any way to filter the feed on the server side so I don't need to get down a lot of data for a few pictures?
It's easier to do in FQL than with the Graph API:
SELECT post_id, actor_id, message, attachment, place, created_time, likes, description
FROM stream WHERE source_id = me() AND actor_id = me()
AND attachment.fb_object_type = 'photo'
Facebook has added a filter parameter to the /me/home endpoint so if you query /me/home?filter=photos you get only photos from the users News Feed

Receive specific feeds from facebook using graph api

I am developing an IPhone app. The user can post to his wall and now I want to read ONLY the news feeds that was posted from the IPHone app.
When I use
https://graph.facebook.com/me/feed?access_token=...
I get all wall posts, and I can recognize the one posted from the iphone app by the "application" node in the JSON response. How can I filter those feeds? Should I use FQL instead?
Thanks!!!
Edit: I tried using https://graph.facebook.com/search?q={My application name}&type=post&access_token= with no success...
Yep, FQL is the way forward, you can pass an app_id: http://developers.facebook.com/docs/reference/fql/stream/
So your query could be like: SELECT post_id, actor_id, target_id, message FROM stream WHERE source_id = me() AND app_id = 'my_app_id'