Coex Chotrawee
Coex Chotrawee

Reputation: 23

Groups api return empty string

Please help me get group list from facebook api.

When I use this code:

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

It returns empty array.

Or if I cut the access token off it still doesn't work.

But when I call the graph api with:

https://graph.facebook.com/me/groups?access_token=....

It returns all of groups, and when I use:

$groups = file_get_contents('https://graph.facebook.com/me/groups?access_token='.$token);

It returns empty json too.

How do I solve it?

Upvotes: 2

Views: 1487

Answers (1)

ogzd
ogzd

Reputation: 5692

I believe that you need to add user_groups permission in order to get the result.

When you facebook login:

FB.login(function(response) {
      if (response.authResponse) {
          ...
      } else {
        ....
      }
  }, {scope: 'user_groups'});

EDIT:

With using Facebook PHP SDK:

$loginUrl = $facebook->getLoginUrl(array('scope' => 'user_groups'));

Upvotes: 1

Related Questions