You can work with Meta Content Library API within Meta Researcher Platform or within an approved third-party cleanroom environment. The getting started procedure documented here is specific to Researcher Platform which runs a modified version of Jupyter and provides you with a virtual data cleanroom where you can securely search for and analyze data. If you are accessing the Content Library API through a third-party cleanroom environment, you will be provided with getting started instructions from the cleanroom's system administrator.
If you are accessing the Content Library API through a third-party cleanroom environment such as the one provided by ICPSR, you will be provided with getting started instructions from the cleanroom's system administrator. Please be sure to follow their instructions as this page only provides information relevant to the Meta Researcher Platform cleanroom.
To get up and running with Content Library API in Researcher Platform:
After January 7, 2025, access to Content Library API in Researcher Platform will require Amazon WorkSpaces Secure Browser. See WorkSpaces Secure Browser in the Researcher Platform documentation for more information. You will not lose any data in this transition. With WorkSpaces Secure Browser, you do not need a VPN to access Researcher Platform. The Log in to the Researcher Platform URL section on this page provides the URL so you can try it.
Until January 7, 2025, you can access Content Library API through a Virtual Private Network (VPN). This section shows you how to install and configure the OpenVPN client and connect to our VPN server. Once connected, you will be able to use Content Library API.
When the setup wizard completes, OpenVPN Connect launches and you will be required to accept the OpenVPN Inc. Data Collection, Use and Retention policy to continue.
In the Import Profile window, select the UPLOAD FILE tab.
Clicking this link downloads the OpenVPN configuration file (fortVpnCredentials.ovpn) to your computer (check your downloads folder). Once downloaded, drag and drop the file into the Import Profile window.
In the Imported Profile window, click CONNECT.
Once successfully connected, you will see this window:
While you are connected to our VPN server, all of your internet traffic is routed through it, so be sure to disconnect when you are finished.
While connected to the VPN, go to the Researcher Platform URL.
If you'd like to use the latest Amazon WorkSpaces Secure Browser version of Researcher Platform, you can follow this URL without being connected to the VPN.
Log in to the site using your Facebook credentials. This will spin up an instance of JupyterHub server for your use in the Researcher Platform.
You will be offered the choice of CPU or GPU server. You can learn more about the difference between the two here and there is complete documentation on Researcher Platform here.
To create a new notebook:
In your Jupyter hub environment, click the blue "+" symbol in the upper left corner of the window.
Under Notebook in the Launcher tab, select Python 3 or R according to your preferred language. This creates and opens a new Jupyter notebook.
To name the notebook, right-click the notebook in the left navigation bar and select Rename.
You enter queries in the blank cells of the notebook. To run a query, click the play icon.
All calls are made using the Content Library API Client. You only need to import the Content Library API client once per Jupyter notebook server session.
In code block examples in this documentation, select the R or Python tab to see the corresponding code. You can copy the code and paste it into your notebook.
library(reticulate)
client <- import("metacontentlibraryapi")$MetaContentLibraryAPIClient
# Set specific MCL_API_VERSION, or use client$LATEST_VERSION to get the latest
client$set_default_version(client$LATEST_VERSION)
Test your setup by running a basic search query. Here is an example to try for Facebook Pages:
library(reticulate)
client <- import("metacontentlibraryapi")$MetaContentLibraryAPIClient
client$set_default_version(client$LATEST_VERSION)
# Search for Facebook Pages
pages_response <- client$get(
path="search/facebook_pages",
params = list("q"="mountains")
)
jsonlite::fromJSON(pages_response$text, flatten=TRUE) # Display first page
Test fetching an entity by its ID (obtained from the results of a previous search) such as one of the Pages from the previous query:
pages_data <- jsonlite::fromJSON(pages_response$text, flatten=TRUE)$data
page_mcl_id <- pages_data[c('id')][1,]
# Fetch by Meta Content Library ID
response <- client$get(path=page_mcl_id)
jsonlite::fromJSON(response$text, flatten=TRUE)