Philip Danks
Philip Danks

Reputation: 57

How to get a list of facebook groups for a user using graph api

Could someone point me in the right direction to how I can get a list of all the groups a specific user is connected to using the facebook graph api?

I have this:

$groups = $facebook->api( '/me/groups', 'GET', array( 'access_token=' => $membertoken ) );

If I use print_r($groups) I can see the array is returning all the groups, but how can I seperate the array to list just the group names and group ID into seperate strings so I can use them in a database etc?

Upvotes: 3

Views: 10815

Answers (1)

cpilko
cpilko

Reputation: 11852

Try this:

print "<h2>Here are the groups you follow:</h2>\n<ul>";
foreach ($groups['data'] as $group) {
    $group_name = $group['name'];
    $group_id = $group['id'];
    printf("<li>%s - ID = %s</li>\n", $group_name, $group_id);
}
print "</ul>";

Upvotes: 1

Related Questions