Likes, User Posts, Photos, and Videos
Learn how to get users' likes, posts, photos, and videos.
We'll cover the following
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 |
| String | Mandatory | This is the token that we received after app authentication and authorization. |
| String | Mandatory | This is the ID of the user. Note that this is a path parameter. |
| String | Optional | These are the fields we want in the response from the API call. |
| 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.
// Importing libraries hereimport fetch from "node-fetch"// Define endpoint URL hereconst endpointUrl = new URL("https://graph.facebook.com/v16.0/{{USER_ID}}/likes");const headerParameters = {contentType: "application/json",};// Setting API call optionsconst options = {method: "GET",headers: headerParameters,};// Define Query Parameters hereconst queryParameters = new URLSearchParams({access_token: '{{USER_ACCESS_TOKEN}}',limit: '10'});// Function to make API callasync function fetchUserLikes() {try {endpointUrl.search = queryParameters;const response = await fetch(endpointUrl, options);// Printing responseprintResponse(response);} catch (error) {// Printing error messageprintError(error);}}// Calling function to make API callfetchUserLikes();
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 thelimit
to10
to specify the maximum number of results to return in response in thequeryParameters
variable.Line 27: We use the
fetch
function to make the API call.
Response Fields
Name | Type | Description |
| String | This is the ID of the liked object. |
| String | This is the name of the liked object. |
| String | This is the category of the liked object. |
| DateTime | This is the time the post was created. The time is in ISO 8601 format. |
| String | This is the description of the liked object. |
| Boolean | If the object is published, then |
| Object | This is the information about the pagination of the feed. It contains fields such as |
| Object | This is a summary of the feed containing information such as |
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 |
| String | Mandatory | This is the token that we received after app authentication and authorization. |
| String | Mandatory | This is the ID of the user. Note that this is a path parameter. |
| String | Optional | These are the fields we want in the response from the API call. |
| 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.
// Importing libraries hereimport fetch from "node-fetch"// Define endpoint URL hereconst endpointUrl = new URL("https://graph.facebook.com/v16.0/{{USER_ID}}/posts");const headerParameters = {contentType: "application/json",};// Setting API call optionsconst options = {method: "GET",headers: headerParameters,};// Define Query Parameters hereconst queryParameters = new URLSearchParams({access_token: '{{USER_ACCESS_TOKEN}}',fields: 'message,full_picture,link,created_time,privacy',limit: '10'});// Function to make API callasync function fetchUserPosts() {try {endpointUrl.search = queryParameters;const response = await fetch(endpointUrl, options);// Printing responseprintResponse(response);} catch (error) {// Printing error messageprintError(error);}}// Calling function to make API callfetchUserPosts();
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 thelimit
to10
to specify the maximum number of results to return in response, and specify thefields
we want in the response from the API call in thequeryParameters
variable.Line 28: We use the
fetch
function to make the API call.
Response Fields
Name | Type | Description |
| String | This is the ID of the post. |
| String | This is the post's text, if it was a text-based post. |
| String | This is the post's text, if it was a story-based post. |
| DateTime | This is the time the post was created. Time is in ISO 8601 format. |
| String | This is the URL of the full-sized version of the attached image. |
| Object | This is the information about the privacy settings of the post. |
| String | This is the link to the post on Facebook. |
| String | This is the type of the post. |
| Object | This is the information about the pagination of the feed. It contains fields such as |
| Object | This is a summary of the feed containing information such as |
Photos and videos
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 |
| String | Mandatory | This is the token that we received after app authentication and authorization. |
| String | Mandatory | This is the ID of the user. Note that this is a path parameter. |
| String | Optional | These are the fields we want in the response from the API call. |
| 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.
// Importing libraries hereimport fetch from "node-fetch"// Define endpoint URL hereconst endpointUrl = new URL("https://graph.facebook.com/v16.0/{{USER_ID}}/photos");const headerParameters = {contentType: "application/json",};// Setting API call optionsconst options = {method: "GET",headers: headerParameters,};// Define Query Parameters hereconst queryParameters = new URLSearchParams({access_token: '{{USER_ACCESS_TOKEN}}',type: 'uploaded',fields: 'name,link,created_time', // Comment out this parameter when calling video endpointlimit: 10});// Function to make API callasync function fetchUserPhotos() {try {endpointUrl.search = queryParameters;const response = await fetch(endpointUrl, options);// Printing responseprintResponse(response);} catch (error) {// Printing error messageprintError(error);}}// Calling function to make API callfetchUserPhotos();
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 thelimit
to10
to specify the maximum number of results to return in response, and specify thefields
that we want in the response from the API call in thequeryParameters
variable.Line 28: We use the
fetch
function to make the API call.
Note: Replace
/photos
with/videos
in theendpointUrl
variable on line 5 and click the “Run” button to see the response for calling thevideo
edge of theuser
object.
Response Fields
Name | Type | Description |
| String | This is the unique identifier for the photo. |
| String | This is the URL of a thumbnail-sized version of the photo. |
| String | This is the name of the given photo. |
| Array | This is an array of objects that contain information about the different sizes of the photo. The objects include width, height, and source. |
| String | This is the link to the photo. |
| String | This is the URL of the photo's icon-sized image. |
| String | This is the photo's width in pixels. |
| String | This is the photo's height in pixels. |
| DateTime | This is the time when the photo was created. The time is in ISO 8601 format. |
| DateTime | This is the last time the photo was updated. The time is in ISO 8601 format. |
| Object | This is the information about the pagination of the feed. It contains fields such as |
| Object | This is a summary of the feed containing information such as |