Guide to Facebook posts data

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.

Parameters

Parameter Type Description

Q
Optional

String

Keyword(s) to search for. See Advanced search guidelines for information about how multiple keyword searches with Boolean operators are handled.

SEARCH_SCOPE
Optional

Enum

Search scope option with two possible values:

  • post_text_only (default) returns only text-only posts.
  • post_text_and_image_text returns text-only and text-in-image posts (not applicable to content other than text and images).

FIELDS
Optional

List

Comma-separated list of Facebook post fields you want included in search results. See Data dictionary for descriptions of all available fields.

POST_IDS
Optional

List

Comma-separated list of Meta Content Library post IDs as strings. Limits the query to posts in the list. Maximum of 250 IDs.

PAGE_IDS
(Deprecated as of version 4.0)

List

This parameter is no longer available. You can use the SURFACE_IDS parameter instead, which accepts Meta Content Library IDs from any eligible Facebook post surface to filter by surface without specifying the type.

PROFILE_IDS
(Deprecated as of version 4.0)

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.

GROUP_IDS (Deprecated as of version 4.0)

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.

EVENT_IDS (Deprecated as of version 4.0)

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.

SURFACE_IDS
Optional

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.

SORT
Optional

Enum

Sort mode specifying the order in which posts are returned (only available for synchronous searches). Available options:

  • newest_to_oldest: Posts are returned in reverse chronological order (newest first).
  • oldest_to_newest: Posts are returned in chronological order (oldest first).
  • most_to_least_views: Posts are returned based on the number of views (most views first).

Default: most_to_least_views

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 newest_to_oldest with the sort parameter in your query.

LANG
Optional

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 (lang="ru,es") or in an array (lang=["ru" "es"]).

LINK
Optional with the q parameter

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:

  • Can only be used with the q parameter.
  • Returns posts from exact matches only.
  • Searching for multiple URLs in one query is not supported.

If you want to search all posts from a domain, the link parameter is not the best option since it returns posts from exact matches only.

Instead, you can use the q parameter where q=url. Results would include all posts in which the value of q is at least a part of the URL in the post. For example, posts from cnn.com/entertainment would be included in a search for cnn.com. Once you have the larger set of results, you can write Python or R code in your Jupyter environment to narrow them down.

IS_BRANDED_CONTENT
Optional

Boolean

Indicates whether the Facebook posts returned can include branded content or not. Learn more.

MEDIA_TYPES
(deprecated as of version 5.0) Optional

List

Starting with version 5.0, you can use the CONTENT_TYPES parameter instead. Comma-separated list of media types to be included in the search results. Media types include albums, photos, videos (including reels), links, reshares and status.

CONTENT_TYPES
Optional

List

Comma-separated list of content types to be included in the search results. Content types include albums, photos, videos (including reels), links, stories, reshare and status.

ADMIN_COUNTRIES
(deprecated as of version 4.0)

List

Starting with version 4.0, you can use the SURFACE_COUNTRIES parameter instead.

SURFACE_COUNTRIES
Optional

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 surface_types is page or profile, whether or not the surface_types parameter has been set. Takes ISO Alpha-2 Country Code in 2-letter uppercase format.

OWNER_TYPES (deprecated as of version 4.0)

List

Starting with version 4.0, you can use the SURFACE_TYPES parameter instead.

SURFACE_TYPES
Optional

List

Comma-separated list of post surface types included in the search results. Possible values are page, profile, group and event.

VIEWS_BUCKET_START
Optional

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_BUCKET_END to define a range.


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.

VIEWS_BUCKET_END Optional

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_BUCKET_START to define a range.


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.

SINCE
Optional

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.

  • If both SINCE and UNTIL are included, the search includes the time range defined by those values.
  • If SINCE is included and UNTIL is omitted, the search includes the SINCE time through the present time.
  • If SINCE is omitted and UNTIL is included, the search goes from the beginning of Facebook time through the UNTIL time.
  • If SINCE and UNTIL are both omitted, the search goes from the beginning of Facebook time to the present time.
  • If SINCE and UNTIL are the same UNIX timestamp, the search includes the SINCE time through the SINCE time plus one hour.
  • If SINCE and UNTIL are the same Date (YYYY-MM-DD), the search includes the SINCE date through the SINCE date plus one day.

UNTIL
Optional

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.

  • If both SINCE and UNTIL are included, the search includes the time range defined by those values.
  • If SINCE is included and UNTIL is omitted, the search includes the SINCE time through the present time.
  • If SINCE is omitted and UNTIL is included, the search goes from the beginning of Facebook time through the UNTIL time.
  • If SINCE and UNTIL are both omitted, the search goes from the beginning of Facebook time to the present time.
  • If SINCE and UNTIL are the same UNIX timestamp, the search includes the SINCE time through the SINCE time plus one hour.
  • If SINCE and UNTIL are the same Date (YYYY-MM-DD), the search includes the SINCE date through the SINCE date plus one day.

Sample queries

Search for posts by keyword

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
}
from metacontentlibraryapi import MetaContentLibraryAPIClient as client

client.set_default_version(client.LATEST_VERSION)

response = client.get(
    path="search/facebook_posts",
    params={"q": "cybercrime"}
)
display(response.json()) # Display first page

# Fetch next page
if client.has_next_page(response):
    response = client.query_next_page(response)
    display(response.json()) # 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).

Search for posts containing specific content types

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")
)
# Search for Facebook story highlights
response = client.get(
    path="search/facebook_posts",
    params={"q":"example","content_types":["stories"]},
)

Search for posts by post ID

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"))
)
#Search for posts with specific post IDs
response = client.get(
        path="search/facebook_posts",
        params={"post_ids": ["877107953929200"]}
)

Search for posts made to specific Facebook Pages, profiles, groups, or events

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 Page IDs
response = client.get(
        path="search/facebook_posts",
        params={"surface_ids": ["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 group IDs   
response = client.get(
        path="search/facebook_posts",
        params={"surface_ids": ["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 Profile IDs 
response = client.get(
        path="search/facebook_posts",
        params={"surface_ids": ["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 event IDs
response = client.get(
        path="search/facebook_posts",
        params={"surface_ids": ["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"))
)
# Search for posts made to specific Page IDs and specific group IDs    

response = client.get(
        path="search/facebook_posts",
        params={"surface_ids": ["282820031228465", "339983685122355"]}
)

Request specific fields

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
# Return only specific list of fields
response = client.get(
    path="search/facebook_posts",
    params={"q": "cybercrime", "fields": "id,text,lang"}
)
display(response.json()) # Display first page

Search for Facebook posts containing a specific URL

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
# Search including both the `q` and `link` parameters:
        
response = client.get(
    path="search/facebook_posts",
    params={"q": "nike", "link": "https://nike.com"}
)
display(response.json()) # Display first page

Search for posts containing images with the search term

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")
)
# Search for facebook posts with images containing query term
response = client.get(
    path="search/facebook_posts",
    params={"q":"example","search_scope": "post_text_and_image_text"}
)

Including multimedia in search results: Third-party cleanroom environment only

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.