You can perform Facebook post searches by calling the Meta Content Library API client get()
method with the search/facebook_posts
path. This document describes the parameters, and shows how to perform basic queries using the method.
All of the examples in this document are taken from a Researcher Platform use case and assume you have created a Jupyter notebook and a client object. See Getting started to learn more.
See Data dictionary for detailed information about the fields that are available on a Facebook post node.
Parameter | Type | Description |
---|---|---|
| String | Keyword(s) to search for. See Advanced search guidelines for information about how multiple keyword searches with Boolean operators are handled. |
| Enum | Search scope option with two possible values:
|
| List | Comma-separated list of Facebook post fields you want included in search results. See Data dictionary for descriptions of all available fields. |
| List | Comma-separated list of Meta Content Library post IDs as strings. Limits the query to posts in the list. Maximum of 250 IDs. |
| List | This parameter is no longer available. You can use the |
| List | Comma-separated list of Meta Content Library Profile IDs as strings. Limits the query to posts from Profiles in the list. Maximum of 250 IDs. |
| List | Comma-separated list of Meta Content Library group IDs as strings. Limits the query to posts from groups in the list. Maximum of 250 IDs. |
| List | Comma-separated list of Meta Content Library event IDs as strings. Limits the query to posts from events in the list. Maximum of 250 IDs. |
| String | Comma-separated list of Meta Content Library IDs from post surfaces as strings. Limits the query to posts made to the surfaces in the list. Maximum of 250 IDs. |
| Enum | Sort mode specifying the order in which posts are returned (only available for synchronous searches). Available options:
Default: Note: Searches conducted in versions earlier than 5.0 had responses sorted in newest-to-oldest order by default. To achieve that same order, you must now specify |
| String | The content languages of the Facebook posts to include, specified as ISO 639-1 language codes in 2-letter lowercase format. Multiple languages are comma-separated either in a single string ( |
| String | Posts containing the specified URL are included in search results. All forms of the URL that point to the same piece of content will be returned. Usage:
If you want to search all posts from a domain, the Instead, you can use the |
| Boolean | Indicates whether the Facebook posts returned can include branded content or not. Learn more. |
| List | Starting with version 5.0, you can use the |
| List | Comma-separated list of content types to be included in the search results. Content types include |
| List | Starting with version 4.0, you can use the |
| List | Comma-separated list of countries by which to filter posts made to Facebook Pages and profiles using the country location from the transparency section. Only returns posts for which |
| List | Starting with version 4.0, you can use the |
| List | Comma-separated list of post surface types included in the search results. Possible values are |
| Integer | Facebook posts with view counts larger than or equal to this number match the search criteria. Range is from 0 to the maximum of more than 100 million. Used with Views are the number of times the post or reel was on screen, not including times it appeared on the post owner’s screen. See Data Dictionary for more details. |
| Integer | Facebook posts with view counts smaller than or equal to this number match the search criteria. Range is from 0 to the maximum of more than 100 million. Used with Views are the number of times the post or reel was on screen, not including times it appeared on the post owner’s screen. See Data dictionary for more details. |
| String or Integer | Date in YYYY-MM-DD (date only) or UNIX timestamp (translates to a date and time to the second) format. Facebook posts created on or after this date or timestamp are returned (used with UNTIL to define a time range). SINCE and UNTIL are based on UTC time zone, regardless of the local time zone of the user who made the post.
|
| String or Integer | Date in YYYY-MM-DD (date only) or UNIX timestamp (translates to a date and time to the second) format. Facebook posts created on or before this date or timestamp are returned (used with SINCE to define a time range). SINCE and UNTIL are based on UTC time zone, regardless of the local time zone of the user who made the post.
|
To search for all public posts on Facebook Pages, groups, profiles, and events that contain specific keywords, use the q
parameter. See Advanced search guidelines for information about how multiple keyword searches are handled.
library(reticulate)
client <- import("metacontentlibraryapi")$MetaContentLibraryAPIClient
client$set_default_version(client$LATEST_VERSION)
response <- client$get(
path="search/facebook_posts",
params = list("q"="cybercrime")
)
jsonlite::fromJSON(response$text, flatten=TRUE) # Display first page
# Fetch next page
if (client$has_next_page(response)) {
response <- client$query_next_page(response)
jsonlite::fromJSON(response$text, flatten=TRUE) # Display second page
}
This example shows how to iterate through responses by using the query_next_page()
method. You can keep calling query_next_page()
to get the next page of 10 results, until all the search results have been returned or the limit of 1,000 for synchronous search has been reached. You can call has_next_page() to check if there is more data. See Search guide for other display and storage options.
The API only returns posts made to Facebook Pages, profiles, groups, or events that can be returned on their respective paths (search/facebook_pages
, search/facebook_profiles
, search/facebook_groups
and search/facebook_events
).
Use the content_types
parameter to specify content types you want included in search results.
# Search for Facebook story highlights
response <- client$get(
path="search/facebook_posts",
params=list("q"="example", "content_types"="stories")
)
To search for posts with specific post IDs (that you obtained from a previous post search), use the post_ids
parameter specifying a list of post IDs to include in the results.
# Search for posts with specific post IDs
response <- client$get(
path="search/facebook_posts",
params = list("post_ids"=list("877107953929200"))
)
Searching for posts made to specific Facebook Pages, profiles, groups, or events requires that you first obtain Page, group, or event IDs by searching using the search/facebook_pages
, search/facebook_profiles
, search/facebook_groups
and search/facebook_events
paths. The search results will include the ID field by default (you don't have to specify it in your query). See Guides to learn about these methods.
The IDs that are displayed in the search results are Meta Content Library IDs that protect user privacy and will not match the IDs of the content on Meta platforms. These Meta Content Library IDs are the ones you use in your subsequent post searches.
To search posts made to specific Pages, profiles, groups, or events, use the surface_ids
parameter with the page_ids
, profile_ids
, group_ids
, or event_ids
parameter, and with or without the q
parameter. q
is not required but can be added to further filter posts. It does not matter when the posts were created. If you omit the q
parameter, all public posts on the specified Pages, profiles, groups, or events are returned.
# Search for posts made to specific Page IDs
response <- client$get(
path="search/facebook_posts",
params = list("surface_ids"=list("282820031228465"))
)
# Search for posts made to specific group IDs
response <- client$get(
path="search/facebook_posts",
params = list("surface_ids"=list("339983685122355"))
)
# Search for posts made to specific Profile IDs
response <- client$get(
path="search/facebook_posts",
params = list("surface_ids"=list("755732639815385"))
)
# Search for posts made to specific event IDs
response <- client$get(
path="search/facebook_posts",
params = list("surface_ids"=list("1025592588867344"))
)
# Search for posts made to specific Page IDs and specific group IDs
response <- client$get(
path="search/facebook_posts",
params=list("surface_ids"=list("282820031228465","339983685122355"))
)
To have the API return only specific fields on any Facebook posts in the response, use the fields
parameter and a comma-separated list of fields you want included. If omitted, default fields will be returned. In the following example, only id
, text
and lang
fields are included:
# Return only specific list of fields
response <- client$get(
path="search/facebook_posts",
params = list("q"="cybercrime", "fields"="id,text,lang")
)
jsonlite::fromJSON(response$text, flatten=TRUE) # Display first page
To search for all public posts made to Facebook Pages, profiles, groups, and events that contain specific keywords and a specific URL, use the q
and link
parameters. The link
parameter cannot be used without the q
parameter. See Advanced search guidelines for information about how multiple keyword searches are handled.
All forms of the URL that point to the same piece of content will be returned. Searching for multiple URLs in one query is not supported.
# Search including both the `q` and `link` parameters:
response <- client$get(
path="search/facebook_posts",
params = list("q"="nike", "link"="https://nike.com")
)
jsonlite::fromJSON(response$text, flatten=TRUE) # Display first page
To search for Facebook posts that include images containing a search term, use the search_scope
parameter. In the following example, the query returns text-only and text-in-image posts:
# Search for facebook posts with images containing query term
response <- client$get(
path="search/facebook_posts",
params=list("q"="example", "search_scope"="post_text_and_image_text")
)
If you are using the Meta Content Library API in an approved third-party cleanroom environment (as opposed to Meta's Researcher Platform), and if that environment supports it, you have the option of including multimedia (photo, video) in your search results. Multimedia in posts from Facebook Pages, profiles, groups, and events are all eligible.
Include the keyword multimedia
in your query (fields
parameter).
For any media contained in a post, the response will include the type of media (photo, video), an ID, and either the media itself or a link to where the cleanroom environment has stored the media. Whether the media can be displayed directly in the response or not depends on the third-party cleanroom interface.
The number of calls allowed that include multimedia is controlled by a multimedia query budget specific to the third-party cleanroom environment. See Rate limiting and query budgeting for multimedia for more information.