我无法使用 C# 使用 Facebook SDK 5.1 检索我的群组

发布于 2024-12-01 07:12:45 字数 326 浏览 2 评论 0原文

我正在使用 Facebook SDK,并尝试使用 C# 来获取用户订阅的组。代码如下

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

执行此代码后我得到一个空对象。这是我缺少的东西吗?

点赞 (JsonObject Groups = (JsonObject)client.Get("me/likes");) 和朋友 (JsonObject Groups = (JsonObject)client.Get("me/朋友”);) 工作正常。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

恏ㄋ傷疤忘ㄋ疼 2024-12-08 07:12:45

您需要提示用户 user_groups 扩展权限。

You need to prompt the user for user_groups extended permission.

酒中人 2024-12-08 07:12:45

由于我遇到了同样的问题并且无法在任何地方找到帮助,因此我想我应该按照@DustyRoberts 的要求解释如何解决该问题。

如果您在请求 me/groups{user-id}/groups 时得到空对象,这是因为您缺少 user_management_groups 权限(是 Graph API 版本 2.3 之前的 user_groups)。

您可以通过在用户登录时添加 scope 参数来实现此目的。这是一个以逗号分隔的权限列表。您可以查看完整的权限列表此处 (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);
    }

有关检查权限的更多信息 此处 (v2.4)

我希望这对某人有帮助,因为这正是我使其工作所需的信息。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文