Likes, User Posts, Photos, and Videos

Learn how to get users' likes, posts, photos, and videos.

User's likes

A user's likes on Facebook are a way for them to show support and interest in the things that matter to them on the platform. Users can like pages, people, or content that they follow, and they are displayed on the user's profile for others to see. By liking a page, person, or piece of content, the user can stay up-to-date with new information from that source. Users can interact with each other's likes by commenting, sharing, or reacting to posts, and they can also use the filters on the left side of the page to customize what they see. This allows users to tailor their experience on Facebook to their specific interests and preferences. In addition to providing a personalized experience, a user's likes can also serve as a way for others to learn more about the user and what they care about. By looking at a user's likes, others can sense the user's personality, interests, and values. The base URL for this endpoint is:

https://graph.facebook.com/v16.0/{user_id}/likes

Request Parameters

Parameter

Type

Category

Description

access_token

String

Mandatory

This is the token that we received after app authentication and authorization.

user_id

String

Mandatory

This is the ID of the user. Note that this is a path parameter.

fields

String

Optional

These are the fields we want in the response from the API call.

limit

String

Optional

This specifies the maximum number of results we want in the response.

To access a user's likes using the Facebook Graph API, we have to make a GET request to the feed edge with the user's ID and an access token with the user_likes permission. The code below uses the endpoint above to fetch users' likes. Click the “Run” button to see the response.

Press + to interact
// Importing libraries here
import fetch from "node-fetch"
// Define endpoint URL here
const endpointUrl = new URL("https://graph.facebook.com/v16.0/{{USER_ID}}/likes");
const headerParameters = {
contentType: "application/json",
};
// Setting API call options
const options = {
method: "GET",
headers: headerParameters,
};
// Define Query Parameters here
const queryParameters = new URLSearchParams({
access_token: '{{USER_ACCESS_TOKEN}}',
limit: '10'
});
// Function to make API call
async function fetchUserLikes() {
try {
endpointUrl.search = queryParameters;
const response = await fetch(endpointUrl, options);
// Printing response
printResponse(response);
} catch (error) {
// Printing error message
printError(error);
}
}
// Calling function to make API call
fetchUserLikes();

In the code widget above:

  • Line 5: We define the endpoint URL in the endpointUrl variable.

  • Lines 18–21: We add the access_token and set the limit to 10 to specify the maximum number of results to return in response in the queryParameters variable.

  • Line 27: We use the fetch function to make the API call.

Response Fields

Name

Type

Description

id

String

This is the ID of the liked object.

name

String

This is the name of the liked object.

category

String

This is the category of the liked object.

created_time

DateTime

This is the time the post was created. The time is in ISO 8601 format.

description

String

This is the description of the liked object.

is_published

Boolean

If the object is published, then true. If it's not published, then false.

paging

Object

This is the information about the pagination of the feed. It contains fields such as next and previous, which we can use to retrieve the next and previous pages of the feed, respectively.

summary

Object

This is a summary of the feed containing information such as total_count (number of total posts in the feed) and can_like (indicating whether or not the feed can be liked).

User's posts

A user's posts are updates, photos, and other content they share on Facebook. The user's friends and followers can see these posts, and they allow the user to share their thoughts, experiences, and opinions with their social network. A user's posts can be a way to stay connected with their friends and loved ones and keep up with the latest happenings. They can also be a way for the user to express themselves and share their personality with others. Users can customize their posts by adding text, hashtags, or other content, and they can also choose who can see their posts using the privacy settings. This allows users to control how their posts are shared on the platform. The base URL for this endpoint is:

https://graph.facebook.com/v16.0/{user_id}/posts

Request Parameters

Parameter

Type

Category

Description

access_token

String

Mandatory

This is the token that we received after app authentication and authorization.

user_id

String

Mandatory

This is the ID of the user. Note that this is a path parameter.

fields

String

Optional

These are the fields we want in the response from the API call.

limit

String

Optional

This specifies the maximum number of results we want in the response.

To retrieve a user's posts using the Facebook Graph API, we will need to make a GET request to the posts edge of the user object using the user's ID and an access token with the user_posts permissions. The code below calls the endpoint above to get users' posts. Click the “Run” button to see the response.

Note: For a newly created profile, populate the user feed; otherwise, you'll get an empty list as the API response.

Press + to interact
// Importing libraries here
import fetch from "node-fetch"
// Define endpoint URL here
const endpointUrl = new URL("https://graph.facebook.com/v16.0/{{USER_ID}}/posts");
const headerParameters = {
contentType: "application/json",
};
// Setting API call options
const options = {
method: "GET",
headers: headerParameters,
};
// Define Query Parameters here
const queryParameters = new URLSearchParams({
access_token: '{{USER_ACCESS_TOKEN}}',
fields: 'message,full_picture,link,created_time,privacy',
limit: '10'
});
// Function to make API call
async function fetchUserPosts() {
try {
endpointUrl.search = queryParameters;
const response = await fetch(endpointUrl, options);
// Printing response
printResponse(response);
} catch (error) {
// Printing error message
printError(error);
}
}
// Calling function to make API call
fetchUserPosts();

In the code widget above:

  • Line 5: We define the endpoint URL in the endpointUrl variable.

  • Lines 18–22: We add the access_token, set the limit to 10 to specify the maximum number of results to return in response, and specify the fields we want in the response from the API call in the queryParameters variable.

  • Line 28: We use the fetch function to make the API call.

Response Fields

Name

Type

Description

id

String

This is the ID of the post.

message

String

This is the post's text, if it was a text-based post.

story

String

This is the post's text, if it was a story-based post.

created_time

DateTime

This is the time the post was created. Time is in ISO 8601 format.

full_picture

String

This is the URL of the full-sized version of the attached image.

privacy

Object

This is the information about the privacy settings of the post.

link

String

This is the link to the post on Facebook.

type

String

This is the type of the post.

paging

Object

This is the information about the pagination of the feed. It contains fields such as next and previous, which we can use to retrieve the next and previous pages of the feed, respectively.

summary

Object

This is a summary of the feed containing information such as total_count (number of total posts in the feed) and can_like (indicating whether or not the feed can be liked).

Photos and videos

User photos
User photos

Photos and videos are a powerful and expressive way for people to share their experiences and memories with others on Facebook. Photos and videos allow users to capture and share the moments that matter most to them, whether it's a vacation, a special event, or just a day in their life. Photos and videos can be liked, commented on, or shared by other users, and they can also be tagged with the names of people or pages. This allows users to connect with and engage with their friends and followers more visually and interactively. The base URL for the photos edge of the user object in the Facebook Graph API is:

https://graph.facebook.com/v16.0/{user_id}/photos

The base URL for the videos edge of the user object in the Facebook Graph API is:

https://graph.facebook.com/v16.0/{user_id}/videos

Request Parameters

Parameter

Type

Category

Description

access_token

String

Mandatory

This is the token that we received after app authentication and authorization.

user_id

String

Mandatory

This is the ID of the user. Note that this is a path parameter.

fields

String

Optional

These are the fields we want in the response from the API call.

limit

String

Optional

This specifies the maximum number of results we want in the response.

To retrieve photos and videos using the Facebook Graph API, we will have to make a GET request to the photos or videos edge of the user object, using an access token with the user_photos and user_videos permissions. Replace the user_id with the ID of the user whose photos or videos we want to retrieve. Click the “Run” button below to see the response.

Press + to interact
// Importing libraries here
import fetch from "node-fetch"
// Define endpoint URL here
const endpointUrl = new URL("https://graph.facebook.com/v16.0/{{USER_ID}}/photos");
const headerParameters = {
contentType: "application/json",
};
// Setting API call options
const options = {
method: "GET",
headers: headerParameters,
};
// Define Query Parameters here
const queryParameters = new URLSearchParams({
access_token: '{{USER_ACCESS_TOKEN}}',
type: 'uploaded',
fields: 'name,link,created_time', // Comment out this parameter when calling video endpoint
limit: 10
});
// Function to make API call
async function fetchUserPhotos() {
try {
endpointUrl.search = queryParameters;
const response = await fetch(endpointUrl, options);
// Printing response
printResponse(response);
} catch (error) {
// Printing error message
printError(error);
}
}
// Calling function to make API call
fetchUserPhotos();

In the code widget above:

  • Line 5: We define the endpoint URL in the endpointUrl variable.

  • Lines 18–22: We add the access_token, set the limit to 10 to specify the maximum number of results to return in response, and specify the fields that we want in the response from the API call in the queryParameters variable.

  • Line 28: We use the fetch function to make the API call.

Note: Replace /photos with /videos in the endpointUrl variable on line 5 and click the “Run” button to see the response for calling the video edge of the user object.

Response Fields

Name

Type

Description

id

String

This is the unique identifier for the photo.

picture

String

This is the URL of a thumbnail-sized version of the photo.

name

String

This is the name of the given photo.

images

Array

This is an array of objects that contain information about the different sizes of the photo. The objects include width, height, and source.

link

String

This is the link to the photo.

icon

String

This is the URL of the photo's icon-sized image.

width

String

This is the photo's width in pixels.

height

String

This is the photo's height in pixels.

created_time

DateTime

This is the time when the photo was created. The time is in ISO 8601 format.

updated_time

DateTime

This is the last time the photo was updated. The time is in ISO 8601 format.

paging

Object

This is the information about the pagination of the feed. It contains fields such as next and previous, which we can use to retrieve the next and previous pages of the feed, respectively.

summary

Object

This is a summary of the feed containing information such as total_count (number of total posts in the feed) and can_like (indicating whether or not the feed can be liked).