Group Details
Learn how to get groups using the Facebook Graph API.
We'll cover the following
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.
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 |
| 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. |
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.
// Importing libraries hereimport fetch from "node-fetch"// Define endpoint URL hereconst endpointUrl = new URL("https://graph.facebook.com/v16.0/{{USER_ID}}/groups");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 fetchUserGroups() {try {endpointUrl.search = queryParameters;const response = await fetch(endpointUrl, options);// Printing responseprintResponse(response);} catch (error) {// Printing error messageprintError(error);}}// Calling function to make API callfetchUserGroups();
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
The following are the response fields for the above endpoint.
Name | Type | Description |
| String | This is the ID of the group. |
| String | This is the name of the group. |
| String | These are the privacy settings for the group. |
| Object | This is the object containing the cover photo information for the group. |
| Boolean | This indicates whether the user making the request is an admin of the group. |
| String | This is the number of members in the group. |
| DateTime | This is the time when the group was last 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 |