I have a pro开发者_开发技巧blem with facebook graph api in accessing user's group.
If i access directly with this: https://graph.facebook.com/fb_id/groups?access_token=token
I can access and retrieve group.
However, using php sdk, it returns null. May I know what went wrong?
$info = $facebook->api('https://graph.facebook.com/'.$memberfb.'/groups?access_token='.$membertoken);
$ct = count($info[data]);
$ct return 0.
May I know what went wrong here?
Make sure you acquired the user_groups
permission and then use:
$info = $facebook->api("/$memberfb/groups?access_token=$membertoken");
I'm using the Facebook API, too. And your code is wrong, the right way is:
$info = $facebook->api( '/'.$memberfb.'/groups', 'GET', array( 'access_token=' => $membertoken ) );
$ct = count( $info['data'] );
The facebook permission required is user_groups
The C# code for getting the groups of a user using FacebookSdk on codeplex is as follows
public Dictionary<string,string> GetGroups(string facebookId, string accessToken)
{
FacebookClient facebookClient = new FacebookClient(accessToken);
JsonObject resul = facebookClient.Get("https://graph.facebook.com/me/groups?access_token=" + accessToken) as JsonObject;
Dictionary<string, string> dicGroups = new Dictionary<string, string>();
foreach (JsonObject item in (((KeyValuePair<string, object>)(resul[0])).Value as JsonArray))
{
dicGroups.Add(item["id"].ToString(),item["name"].ToString() );
}
return dicGroups;
}
精彩评论