FQL:stream
Query this table to return posts from a user's stream or the user's profile.
You can get two types of data when you query this table:
- You can get public data (viewable to anyone on Facebook) without needing an extended permission.
- You can get more data if you prompt the user for the read_stream extended permission.
The stream table is really two concepts built into one table. If you specify a filter_key and/or multiple users, the results will behave like the stream in Facebook's home page. If only one user is specified, and no filter_key
is specified, the table will assume that you want a profile-like view, and all that implies.
Those behaviors differ significantly. For example, the homepage-like view only aggregates data over the last few days. The profile-like view gets much older data from our databases. Also, in the case of a page, the profile view also includes posts by fans.
If you want to return all the posts from a user's stream that were published through your application, make sure you include the app_id
in your query.
For example to get a viewing user's stream, use SELECT message FROM stream WHERE filter_key="nf"
.
The stream table is limited to the last 30 days or 50 posts, whichever is greater.
Contents |
Columns
Highlighted rows are indexable / searchable and one is usually required in the WHERE portion of the query.
Name | Type | Description |
---|---|---|
post_id | string | The ID of the post from the user's stream. This field, when used as an index, is primarily used to re-retrieve posts. Otherwise, it is used to specify a post when using any of the stream setters. |
viewer_id | int | The ID of the user whose stream you are querying. The viewer_id defaults to the active session key. |
app_id | int | The application ID for the application through which the post was published. This includes application IDs for Facebook applications like Photos and Video. |
source_id | int | The ID of the user, Page, group, or event whose posts you want to retrieve. This includes both posts that the user or Page has authored (that is, the actor_id is the source_id) and posts that have been directed at this target user, Page, group, or event (that is, the target_id is the source_id). |
updated_time | time | The time the post was last updated, which occurs when a user comments on the post. |
created_time | time | The time the post was published to the user's stream. |
filter_key | string | The filter key to fetch data with. This key should be retrieved from stream.getFilters or querying the stream_filter FQL table. (apparently not returned for Pages) |
attribution | string | For posts published by applications, this is the string that states through which application the post was published. For example, "Joe loves the Social Web (by MicroBloggerApp)." |
actor_id | string | The user ID of the person who is the user taking the action in the post. |
target_id | string | The user or Page to whom the post was directed. |
message | string | The message written by the user. |
app_data | array | An array of application-specific information supplied to Facebook to create the attachment to the post. This information is not needed to render a user's stream in your application, unless you need this information for special handing of your own application posts. This array includes:
|
action_links | array | An array containing the text and URL for each action link. |
attachment | array | An array of information about the attachment to the post. This is the attachment that Facebook returns. |
impressions | int | Number of impressions of this post. This data is visible only if the you have read_insights extended permission of any of the page owners. |
comments | array | A sample array of comments added to a post. This list contains up to two comments to display along with stream content. To get the full list of comments, use stream.getComments or query the comment FQL table using the post_id of this post. The array contains the following fields:
|
likes | array | An array of likes associated with the post. The array contains the following fields:
|
privacy | array | The privacy setting for a post, indicating which of a user's friends or others can see the content. |
type | string | Do not use this field as it's been deprecated. To determine what sort of post gets returned, look for the presence of an attachment (lack of an attachment indicates a status update), and if one is present, look at the attachment's media type (photo, Flash, mp3) to determine how you want to handle the post. Facebook for Adobe AIR uses this method, for example. This column returns following integers: 80 for links, 247 for mobile uploads, 237 for check-ins, 56 for wall posts by someone else, 46 for user's own wall posts, 66 for notes |
permalink | string | A link to the stream post. |
xid | int | When querying for the feed of a live stream box, this is the xid associated with the Live Stream box (you can provide 'default' if one is not available). |
Examples
Get the visible stream of all of a user's connections (regardless of following status).
SELECT post_id, actor_id, target_id, message FROM stream WHERE source_id in (SELECT target_id FROM connection WHERE source_id=<uid>) AND is_hidden = 0
Retrieve a user's home page stream (News Feed) based on the user's following status for his or her connections.
SELECT post_id, actor_id, target_id, message FROM stream WHERE source_id in (SELECT target_id FROM connection WHERE source_id=<uid> AND is_following=1) AND is_hidden = 0
A typical use case for the stream table using a filter_key from the stream_filter FQL table, in this case retrieving the user's News Feed.
SELECT post_id, actor_id, target_id, message FROM stream WHERE filter_key in (SELECT filter_key FROM stream_filter WHERE uid=<uid> AND type='newsfeed') AND is_hidden = 0
Refresh posts by getting new posts newer than some time.
SELECT post_id, actor_id, target_id, message FROM stream WHERE source_id = <source_id> AND updated_time > <newest_time>
Get posts before current set of posts. (use in place of OFFSET).
SELECT post_id, actor_id, target_id, message FROM stream WHERE source_id = <source_id> AND updated_time < <oldest_time> LIMIT 50
Retrieve a user's wall posts (stories on their profile).
SELECT actor_id, message FROM stream WHERE source_id = <user id> limit 50
Retrieve the action links in a user's stream, and remove any HTML markup and encoding.
SELECT strip_tags(action_links) FROM stream WHERE source_id = <user id>
Retrieve the stream for a Live Stream plugin.
SELECT post_id, message FROM stream WHERE app_id = <app id> AND xid = 'default'
See Also
Notes/Bugs/Gotchas
- The stream table is limited to the last 30 days or 50 posts, whichever is greater.
- This is unreliable. If you do not specify a created_time the query will sometimes return a much larger data sample, sometimes from the moment the page was created.
- Requires an active access token
- From June 3 2011 a token is required to query this table. You can use any application or user token to make the query.