ID-based retrieval

This feature allows you to fetch a Meta Content Library entity using its Meta Content Library ID. We support the following entities for ID-based retrieval:

  • Facebook Pages
  • Facebook groups
  • Facebook events
  • Facebook profiles
  • Facebook posts
  • Facebook comments
  • Facebook Marketplace listings
  • Facebook fundraisers
  • Facebook donations
  • Instagram accounts
  • Instagram posts
  • Instagram comments
  • Instagram fundraisers
  • Instagram channels
  • Instagram channel messages
  • Nonprofits

We also support retrieval of nested resources to a entity. A nested resource is a connection between two entities. For example, the Facebook post entity can have comments connected to it.

See Data dictionary for detailed information about the fields on each entity.

Getting started with ID-based retrieval

Meta Content Library IDs can be used in queries and displayed in the search results. Meta Content Library IDs are unique IDs linked to an entity in MCL. These IDs cannot be used to search on Meta technologies.

To get Meta Content Library IDs, submit a query as shown in the Guides. The response to your queries will include the ID field. This ID can be used for ID-based retrieval by following the steps below.

library(reticulate)
client <- import("metacontentlibraryapi")$MetaContentLibraryAPIClient

# Set specific MCL_API_VERSION, or use client$LATEST_VERSION to get the latest
client$set_default_version("MCL_API_VERSION")

# Get the response of MCL ID
response <- client$get(path=”<ENTITY_TYPE>/<MCL_ID>”)

# Display the response
jsonlite::fromJSON(response$text)
from metacontentlibraryapi import MetaContentLibraryAPIClient as client

# Set specific MCL_API_VERSION, or use client.LATEST_VERSION to get the latest
client.set_default_version("MCL_API_VERSION")

# Get the response of MCL ID
response = client.get(path=”<ENTITY_TYPE>/<MCL_ID>”)

# Display the response 
display(response.json())

The following table describes the parameters:

Parameter Type Description

path

String

Entity path (eg /facebook/posts/), followed by Meta Content Library ID

version

Optional [String]

Optional version of Meta Content Library API.

Get nested resource

Below is the syntax for fetching content library ID-based retrieval nested resource:

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)

# Get the response of the nested resource of MCL ID with optional params fields
response <- client$get(
        path="<ENTITY_TYPE>/<MCL_ID>/<NESTED_RESOURCE>/preview",
        params=list("fields" = FIELDS)
)

# Display the response
jsonlite::fromJSON(response$text)
from metacontentlibraryapi import MetaContentLibraryAPIClient as client

# Set specific MCL_API_VERSION, or use client.LATEST_VERSION to get the latest 
client.set_default_version("MCL_API_VERSION")

# Get the response of the nested resource of MCL ID with optional params fields
response = client.get(
        path="<ENTITY_TYPE>/<MCL_ID>/<NESTED_RESOURCE>/preview",
        params={"fields" : FIELDS}
)

# Display the response
display(response.json())

The following table describes the parameters:

Parameter Type Description

PATH

String

Entity path, followed by Meta Content Library ID, followed by edge and /preview suffix.

PARAMS
Optional

List

Comma-separated list of fields you want included in the result. See Data dictionary for descriptions of all available fields.

Sample queries

Fetch Facebook Page by Page ID

# Sample query for Python library for ID-based retrieval of a Facebook page with optional param fields
library(reticulate)
client <- import("metacontentlibraryapi")$MetaContentLibraryAPIClient

client$set_default_version(client$LATEST_VERSION)

# Fetch the entity by calling the get method with optional fields parameter
response <- client$get(
       path="facebook/pages/990512972055041",
       params=list("fields"="about,description")
)

# Print the Meta Content Library entity
jsonlite::fromJSON(response$text, flatten=TRUE)
# Sample query for Python library for ID-based retrieval of a Facebook page with optional param fields
from metacontentlibraryapi import MetaContentLibraryAPIClient as client

client.set_default_version(client.LATEST_VERSION)

# Fetch the entity by calling the get method with optional fields parameter
response = client.get(
        path="facebook/pages/990512972055041",
        params={"fields": "about,description"}
)

# Print the Meta Content Library entity
display(response.json())

Fetch comments on a post

Comments can be fetched both for Facebook and Instagram posts. The following examples use a Facebook post, but the same structure applies to Instagram posts.

library(reticulate)
client <- import("metacontentlibraryapi")$MetaContentLibraryAPIClient

client$set_default_version(client$LATEST_VERSION)

# Fetch comments by calling /comments edge, with a POST Meta Content Library ID
response <- client$get(
        path = "facebook/posts/1927859627616307/comments/preview", 
        params=list("fields"="owner,creation_time")
)

# Fetch results
jsonlite::fromJSON(response$text, flatten=TRUE)
from metacontentlibraryapi import MetaContentLibraryAPIClient as client

client.set_default_version(client.LATEST_VERSION)

# Fetch comments by calling /comments edge, with a Post Meta Content Library ID
response = client.get(
       path="facebook/posts/1927859627616307/comments/preview",
       params={"fields" : "owner,creation_time"}
)
# Fetch results
display(response.json())

The example above returns 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. As described above, the synchronous query can return up to 1,000 results. Asynchronous query should be used instead if there are more than 1,000 comments available.

all_comments <- list()

# Check if a post has next page and if it exists fetch the next page
while  (client$has_next_page(response)) {
     comments <- jsonlite::fromJSON(response$text, flatten = TRUE)$data

     all_comments <- dplyr::bind_rows(all_comments, comments)

     # Get next page
    response <- client$query_next_page(response)
}

# Display the response
all_comments
all_comments = []

# Check if a post has next page
while (client.has_next_page(response)):
    comments = response.json()['data']

    all_comments = all_comments + comments

    # Get next page
    response = client.query_next_page(response)

# Display the response
display(all_comments)