You can perform Instagram posts searches by calling the Meta Content Library API client get()
method, syntax and parameters It also shows how to perform basic queries using the method with the search/instagram_posts
path. This document describes the parameters and shows you how to perform basic queries by using this method.
Public Instagram accounts include professional accounts for businesses and creators. They also include a subset of personal accounts that have privacy set to public and have either a verified badge or 25,000* or more followers. (Version 2.0 requires 50,000 or more followers for the account to be included.) A verified badge in this context refers to accounts confirmed as authentic and not those with a paid Meta Verified subscription.
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. |
| List | Comma-separated list of Instagram post fields to be included in search results. See Data dictionary for descriptions of all available fields. |
| List | Comma-separated list of Meta Content Library post IDs to include in search results. Limits the query to posts in the list. Maximum of 250 IDs. |
| List | Comma-separated list of Meta Content Library account IDs as strings. Limits the query to posts from accounts in the list. Maximum of 250 IDs. |
| List | Comma-separated list of Instagram account types. Possible values are Public Instagram accounts include professional accounts for businesses and creators. They also include a subset of personal accounts that have privacy set to public and have either a verified badge or 25,000 or more followers. A verified badge in this context refers to accounts confirmed as authentic and not those with a paid Meta Verified subscription. *v2.0 will continue to include a subset of personal accounts that have privacy set to public and have either a verified badge or 50,000 or more followers. |
| String | The content languages of the Instagram 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 ( |
| Boolean | Indicates whether the Instagram posts returned can include branded content or not. Learn more. |
| List | Comma-separated list of media types to be included in the search results. Media types include |
| Integer | Instagram 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. 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 | Instagram 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. 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. Instagram 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. Instagram 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.
|
| Enum | Sorting mode in which the posts are returned (only for synchronous endpoint). Available options:
Default value: newest_to_oldest |
To search for all public posts from public Instagram accounts that contain a specific keyword, use get()
method with 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)
# Search for posts with specific keyword
response <- client$get(
path = "search/instagram_posts",
params = list('q' = "cybercrime")
)
# No results are displayed until you provide display instructions:
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 would return only 10 results per page. You can use the query_next_page()
and has_next_page()
to get the next page of 10 results until all the results have been returned. See Search guide for other display and storage options.
The API only returns posts from Instagram accounts that can be returned on their respective paths (search/instagram_accounts
).
To have the API return only specific fields on any Instagram posts in the response, use the get()
method with the fields
parameter and a comma-separated list of fields you want included. If omitted, default fields will be returned.
# Create an endpoint including a list of fields:
response <- client$get(
path = "search/instagram_posts",
params = list('q' = "cybercrime", 'fields'='id,text,creation_time')
)
jsonlite::fromJSON(response$text, flatten=TRUE) # Display first page
To search for posts with specific post IDs (that you obtained from a previous post search), use get()
method with 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/instagram_posts",
params = list('post_ids'=list('7069734086407812'))
)
jsonlite::fromJSON(response$text, flatten=TRUE) # Display first page
Searching for posts from specific Instagram accounts requires that you first obtain account IDs by using get()
method with search/instagram_accounts
path. The search results will include the ID field by default (you don't have to specify it in your query). See Guide to Instagram accounts data to learn about this method.
The IDs that are displayed 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 for posts from specific accounts, use account_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 from the specified accounts are returned.
# Search for posts from specific account IDs
response <- client$get(
path = "search/instagram_posts",
params = list('account_ids'='315242517956050')
)
jsonlite::fromJSON(response$text, flatten=TRUE) # Display first page
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 Instagram business, creator, and personal accounts 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.