Stream (FQL)

From Facebook Developer Wiki

Jump to: navigation, search


Contents

Description

The FQL stream table. Query this table to return posts from a user's stream.

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.

To structure your query, use the table name (stream in this case) in the FROM clause. The items in the Name column correspond to columns in the table that can be referenced in the SELECT and WHERE clauses.

In order to make your query indexable, the WHERE in your query should contain an = or IN clause for one of the columns marked with a * in the Indexable column of the table.

For example to get a viewing user's stream, use SELECT message FROM stream WHERE filter_key="nf".

Columns

IndexableNameTypeDescription
* 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 includes users adding comments or liking 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.
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:
  • tbid (i64): A 64-bit int representing the template bundle ID (for posts that entered the stream through feed.publishUserAction and similar calls that are not part of the Open Stream API).
  • attachment_data (array): An array containing the template data for posts that entered the stream through feed.publishUserAction and similar calls that are not part of the Open Stream API.
  • images (array): A JSON-encoded object containing any images associated with the story. These images are specified in Attachment (Streams) and Template Data, depending upon the call use to create the post originally.
  • action_links (array): An array containing the text and URL for each action link.
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.
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:
  • can_remove (bool): Indicates whether users can remove comments.
  • can_post (bool): Indicates whether users can post comments.
  • count (i32): The total number of comments added to the post.
  • comment_list (array): A list of comment-type comments for this post. Comments are formatted as they would be when returned by the comment (FQL) table.
likes array An array of likes associated with the post. The array contains the following fields:
  • href (string): The URL to a page showing the other users who've liked this post.
  • count (i32): The total number of times users like the post.
  • sample (array): A sample of users who like the post.
  • friends (array): A list of the viewing user's friends who like the post.
  • user_likes (bool): Indicates whether the viewing user likes the post.
  • can_like (bool): Indicates whether the post can be liked.
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, video, Flash, mp3) to determine how you want to handle the post. Facebook for Adobe AIR uses this method, for example.
permalink string A link to the stream post.
tagged_ids array An array of ids that are referred to in the story. Currently, this is commonly encountered in stories about photo tags.
is_hidden bool A flag indicating whether the specified post has been hidden by the viewing user

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>

Notes

  • If you want to remove any HTML markup and encoding for a field in your query (for example, in an attachment), pass the field as a parameter to the strip_tags function. You can specify this function more than once if you want to remove markup from multiple fields.
  • The OFFSET FQL parameter does not work for the stream table (and doesn't really make sense as posts are always being inserted into the stream). To get an "offset" number of posts, query with a time range prior to the oldest time of your current set of posts. Similarly, to get updated posts, specify a time range after the newest time of your current set of posts.
  • You can only make 100 calls to stream per 600 seconds.

See Also

reference