You can perform Facebook Marketplace searches by calling the Meta Content Library API client get() method with the facebook/marketplace-listings/preview 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 Secure Research Environment 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 Marketplace node.
| Parameter | Type | Description |
|---|---|---|
| String | Keyword(s) to search for. Searches listing |
| List | Comma-separated list of listing category names to include in the search. Keywords can be used to match categories. Categories are visible in the Meta Content Library UI and in the Facebook Marketplace mobile app. |
| List | Comma-separated list of Marketplace listing fields you want included in search results. See Data dictionary for descriptions of all available fields. |
| List | Comma-separated list of content types to be included in the search results. Available content types are |
| List | Comma-separated list of countries to include. Takes ISO Alpha-2 Country Code in 2-letter uppercase format. |
| Enum | Sort mode specifying the order in which listings are returned (only available for synchronous searches). Available options:
Additional available options when the
Default: |
| Integer | Minimum price for the search in the currency of the listing country when only a single listing country is included. Not valid when the |
| Integer | Maximum price for the search in the currency of the listing country when only a single listing country is included. Not valid when the |
| Integer | Marketplace listings 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 listing was on screen, not including times it appeared on the seller’s screen. View counts for Marketplace listings are refreshed every 2-3 days. |
| Integer | Marketplace listings 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 listing was on screen, not including times it appeared on the seller’s screen. View counts for Marketplace listings are refreshed every 2-3 days. |
| String or Integer | Date in YYYY-MM-DD (date only) or UNIX timestamp (translates to a date and time to the second) format. Marketplace listings created on or after this date or timestamp are returned (used with
|
| String or Integer | Date in YYYY-MM-DD (date only) or UNIX timestamp (translates to a date and time to the second) format. Marketplace listings created on or before this date or timestamp are returned (used with
|
To search for all public listings on Facebook Marketplace 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="facebook/marketplace-listings/preview", params=list("q"="rentals"))
jsonlite::fromJSON(response$text, flatten=TRUE) # Display first pageUse the price_max parameter to specify the highest price you want included in search results. Remember that this parameter is only valid when a single country is specified using the listing_countries parameter.
response <- client$get(path="facebook/marketplace-listings/preview", params=list("listing_countries"="US", "price_max"="10000", "q"="rentals"))
jsonlite::fromJSON(response$text, flatten=TRUE) # Display first pageTo search for listings in specific categories, use the categories parameter to specify the list of categories to include in the results.
response <- client$get(path="facebook/marketplace-listings/preview", params=list("categories"="Clothing, Shoes & Accessories,Rentals,Books, Movies & Music", "q"="rentals"))
jsonlite::fromJSON(response$text, flatten=TRUE) # Display first pageMultimedia in responses to queries on Secure Research Environment include the type of media (photo, video), a Meta Content Library ID, the duration and any user tags. You can get the URL for the media by querying for ”fields”=”multimedia{url}”.
Multimedia is not included in responses to queries in third-party cleanrooms by default. Third-party cleanroom users can get multimedia by querying for ”fields”=”multimedia”. In addition to the type, Meta Content Library ID, duration and user tags, the URL is included in multimedia responses in third-party cleanrooms. Multimedia is available in posts from Facebook Pages, profiles, groups, and events.
Include the keyword multimedia in your query (fields parameter) on third-party cleanrooms, because multimedia is not included by default.
Include the keyword multimedia{url} in your query (fields parameter) on Secure Research Environment to obtain the media URL, because the URL is not included by default.
To display multimedia in Secure Research Environment use display_media().
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.
To download multimedia content, use download_multimedia_by_content_ids() with a list of known content IDs. See Guide to ID-based retrieval for information on how to retrieve content IDs.
# Load required libraries
library(reticulate)
meta_content_library_api <- import("metacontentlibraryapi")
utils <- meta_content_library_api$MetaContentLibraryAPIMultimediaUtils
# Provide a comma-separated list of content ids as strings
ids_to_download <- c("553170087752425", "681021651202495")
# Download the multimedia content
utils$download_multimedia_by_content_ids(ids_to_download)
# The file path is displayed when the above command is run
utils$display_media(<FILE_PATH>)