3

I am using the Facebook SDK and I am trying with C# to get the groups the user is subscribed to. The code is as follows

JsonObject Groups = (JsonObject)client.Get("me/groups");

After this code executes I get an empty object. Is it something that I am missing?

The sale code for likes (JsonObject Groups = (JsonObject)client.Get("me/likes");) and friends (JsonObject Groups = (JsonObject)client.Get("me/friends");) is working ok.

ekad
  • 14,436
  • 26
  • 44
  • 46

2 Answers2

3

You need to prompt the user for user_groups extended permission.

bkaid
  • 51,465
  • 22
  • 112
  • 128
0

As I was having the same issue and couldn't find help anywhere, I thought I'd necro this with an explanation on how to solve the problem, as requested by @DustyRoberts.

If you get an empty object when requesting me/groups or {user-id}/groups it's because you're lacking the user_managed_groups permission (was user_groups prior to Graph API version 2.3).

You can do this by adding the scope parameter when logging in the user. It's a comma seperated list of permissions. You can see a full list of permissions here (v2.4).

    public static Uri GetLoginUrl(bool rerequestPermissions)
    {
        var client = new FacebookClient();
        dynamic para = new ExpandoObject();
        para.client_id = Settings.AppId;
        para.redirect_uri = Settings.LoginRedirUrl;
        para.response_type = Settings.ResponseType;
        para.scope = Settings.Scope; // Includes user_managed_groups

        // true if you've detected that one or more permissions have been denied
        // or revoked. It'll promt the user to grant the permissions again as when they
        // first used your app.
        if (rerequestPermissions)
            para.auth_type = "rerequest";

        return client.GetLoginUrl(para);
    }

More on checking for permissions here (v2.4)

I hope this helps someone cause it's exactly the information I needed to make it work.

Heki
  • 926
  • 2
  • 15
  • 34
  • what will be the http://graph.facebook ......... link for getting my all joined groups. – Zia Ur Rahman Sep 08 '16 at 11:59
  • @ZiaUrRahman it's detailed in the question, actually. You just need to `Get("me/groups")` and you'll have them, provided you have the permission to do so as per my answer. Otherwise I have misunderstood your question, I'm afraid. – Heki Sep 12 '16 at 07:31
  • thanks for the respond, You r right, I will get the groups like this, but these are the groups which created by Me, and I need the groups which I have joined ... i.e. almost 100 groups I have joined, some are Closed Groups and some are Public Groups, so I need to get the List of all my Joined Groups. Thanks. – Zia Ur Rahman Sep 12 '16 at 07:44
  • Ah, that does pose a real problem. The method to do that has been deprecated in the Graph API. You will only be able to retrieve groups that, as you say yourself, have created or, I think, are admin in. I have difficulty seeing why Facebook made that decision.. I had the same problem as you and it was VERY frustrating. I ended up doing something nasty and reading the HTML and clicking links.. *shudders* but I needed to automate some image cleanup in massive albums. That's another thing, Graph API cannot delete things you (or perhaps even it) didn't create. – Heki Sep 12 '16 at 07:58
  • 1
    Oh! sad to hear the deprecation of such functionality. It means, we have to do manually something with such large list of groups. But anyway, thanks for the info. :) – Zia Ur Rahman Sep 12 '16 at 08:50