【问题标题】:get user group from facebook graph api从 facebook graph api 获取用户组
【发布时间】:2010-12-31 09:37:14
【问题描述】:

我在访问用户组时遇到了 facebook graph api 的问题。

如果我直接访问: https://graph.facebook.com/fb_id/groups?access_token=token

我可以访问和检索组。

但是,使用 php sdk,它返回 null。我可以知道出了什么问题吗?

$info = $facebook->api('https://graph.facebook.com/'.$memberfb.'/groups?access_token='.$membertoken);    
$ct = count($info[data]);

$ct 返回 0。

我可以知道这里出了什么问题吗?

【问题讨论】:

  • 嗨 davidlee,你能告诉我一些事情吗,即使你想将它用于一个组,你是否使用 app_id 和密码初始化 php sdk?我正在尝试访问一个封闭组,但似乎所有文档都没有将我带到正确的方向。谢谢

标签: php facebook facebook-graph-api


【解决方案1】:

确保您获得了user_groups 权限,然后使用:

$info = $facebook->api("/$memberfb/groups?access_token=$membertoken");

【讨论】:

    【解决方案2】:

    我也在使用 Facebook API。而你的代码是错误的,正确的做法是:

    $info = $facebook->api( '/'.$memberfb.'/groups', 'GET', array( 'access_token=' => $membertoken ) );
    $ct = count( $info['data'] );
    

    【讨论】:

      【解决方案3】:

      所需的 facebook 权限是 user_groups

      在codeplex上使用FacebookSdk获取用户组的C#代码如下

      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;
          }
      

      【讨论】:

        猜你喜欢
        • 2011-08-12
        • 2011-08-16
        • 2014-11-21
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多