Group Details

Learn how to get groups using the Facebook Graph API.

Groups on Facebook are a way for users to come together around a common interest or cause and connect with others who share similar interests. Users can use groups for various purposes, such as discussing a hobby or interest, connecting with others with similar experiences, or organizing around a cause or campaign. Businesses, organizations, and communities can also use them to build and engage with their audience, support customers, and share information or resources.

A Facebook group
A Facebook group

Any user can create these groups, and they can be public or private. Public groups have a searchable name and description, and anyone can join, while private groups are by invitation only and have hidden content and members. Admins of the group can control the content and members of the group, approve/reject posts and memberships, and access analytics.

Group details

To view the groups that a user is a part of using the Facebook Graph API, we can make a GET request to the groups edge of the user object using a user access token that has the group_access_member_info and publish_to_groups permissions. The base URL of this endpoint is:

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

Note: For the group endpoints to work, we must have a Facebook group. Refer to this lesson in order to learn how to create a Facebook group.

Request parameters

The following are the request parameters for the above endpoint.

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.

The code below uses the endpoint above to find user groups. We will extract the group ID from the response so that it can be used to make API calls related to groups later. 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}}/groups");
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 fetchUserGroups() {
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
fetchUserGroups();

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

The following are the response fields for the above endpoint.

Name

Type

Description

id

String

This is the ID of the group.

name

String

This is the name of the group.

privacy

String

These are the privacy settings for the group.

cover

Object

This is the object containing the cover photo information for the group.

admin

Boolean

This indicates whether the user making the request is an admin of the group.

member_count

String

This is the number of members in the group.

updated_time

DateTime

This is the time when the group was last 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).