Post 到我是管理员的封闭组

Post to a closed group where Im admin

我有以下代码(facebook C# SDK)post 到 facebook 墙:

public long? UploadPost(string intLinkTitle, string inMessage, string inLinkCaption, string inLinkUrl, string inLinkDescription, string inLinkUrlPicture)
        {
            object obj;
            Facebook.JsonObject jsonObj;
            FacebookClient client;
            string access_token = ConfigurationManager.AppSettings["FacebookPageAccessToken"].ToString();

            client = new FacebookClient(access_token);

            var args = new Dictionary<string, object>();
            args["message"] = inMessage;
            args["caption"] = inLinkCaption;
            args["description"] = inLinkDescription;
            args["name"] = intLinkTitle;
            args["picture"] = inLinkUrlPicture;
            args["link"] = inLinkUrl;

            if ((obj = client.Post("/" + ConfigurationManager.AppSettings["FacebookPageId"].ToString() + "/feed", args)) != null)
            {
                if ((jsonObj = obj as Facebook.JsonObject) != null)
                {
                    if (jsonObj.Count > 0)
                        return long.Parse(jsonObj[0].ToString().Split('_').Last().ToString());
                }
            }

            return null;
        }
    }

只要我 post 到我的 public facebook 网站页面,这就很好用,但是当将 FacebookPageId 更改为组 ID 时,我得到 (FacebookApiException - #200) Permissions error

我的用户是组和页面的管理员。

我已尝试 post 来自 Graph API Explorer 的消息,其中包含以下行:294632750660619/feed/?message=test 但这里存在语法问题,也已尝试 294632750660619/feed?message=test 但没有成功。

如何post加入已关闭的 facebook 群组?

好的,我找到正确的方法了。这是我必须做的:

  1. 转到 https://developers.facebook.com/ 并创建一个新应用程序
  2. 设置 > 添加平台(网站并设置站点 URL(例如 localhost..)
  3. 将应用程序设置为上线(状态和评论 > 是),为此需要在设置 > 联系电子邮件下设置电子邮件地址
  4. 转到Graph API Explorer
  5. 从下拉列表中选择新应用
  6. 单击获取访问令牌
  7. 选择正确的权限(user_groupsuser_statususer_photosmanage_pagespublish_actionsread_insightsread_stream ) 并单击获取访问令牌。现在我们拍了一张短片
  8. 使用此URL(更改参数(3))生成扩展用户令牌(有效期为 60 天):https://graph.facebook.com/oauth/access_token?grant_type=fb_exchange_token&client_id=[app-id]&client_secret=[app-secret]&fb_exchange_token=[short-lived-token]
  9. 在应用程序中使用生成的none 过期访问令牌
  10. 在此处验证访问令牌:https://developers.facebook.com/tools/debug/access_token/

使用此代码上传 post :

public long? UploadPost(string intLinkTitle, string inMessage, string inLinkCaption, string inLinkUrl, string inLinkDescription, string inLinkUrlPicture)
        {
            object obj;
            Facebook.JsonObject jsonObj;
            FacebookClient client;
            string access_token = ConfigurationManager.AppSettings["FacebookPageAccessToken"].ToString();

            client = new FacebookClient(access_token);

            var args = new Dictionary<string, object>();
            args["message"] = inMessage;
            args["caption"] = inLinkCaption;
            args["description"] = inLinkDescription;
            args["name"] = intLinkTitle;
            args["picture"] = inLinkUrlPicture;
            args["link"] = inLinkUrl;

            if ((obj = client.Post("/" + ConfigurationManager.AppSettings["FacebookPageId"].ToString() + "/feed", args)) != null)
            {
                if ((jsonObj = obj as Facebook.JsonObject) != null)
                {
                    if (jsonObj.Count > 0)
                        return long.Parse(jsonObj[0].ToString().Split('_').Last().ToString());
                }
            }

            return null;
        }

要获取提要,请使用:

private void GetFeed()
        {
            object obj;
            Facebook.JsonObject jsonObj;
            Facebook.JsonObject jsonPaging;
            FacebookClient client;
            int pageCount = 0;
            string access_token;
            string URL;
            DateTime fetchFaceBookFeedFromDate;
            DateTime? oldestPostFetched = null;

            fetchFaceBookFeedFromDate = DateTime.Now.AddDays(-30);
            access_token = ConfigurationManager.AppSettings["FacebookPageAccessToken"].ToString();
            URL = "/" + ConfigurationManager.AppSettings["FacebookPageId"].ToString() + "/feed";

            client = new FacebookClient(access_token);


            while (URL.Length > 0 && pageCount < 1000)
            {
                if ((obj = client.Get(URL)) != null)
                {
                    if ((jsonObj = obj as Facebook.JsonObject) != null && jsonObj.Count > 0)
                    {
                        if (jsonObj[0] is Facebook.JsonArray)
                            oldestPostFetched = SaveFacebookForumThread(jsonObj[0] as Facebook.JsonArray, fetchFaceBookFeedFromDate);

                        if (jsonObj.Keys.Contains("paging") && (jsonPaging = jsonObj["paging"] as Facebook.JsonObject) != null && jsonPaging.Keys.Contains("next"))
                            URL = jsonPaging["next"].ToString();
                        else
                            break;
                    }
                }
                pageCount++;

                if (oldestPostFetched.HasValue && fetchFaceBookFeedFromDate > oldestPostFetched)
                    break;
            }
        }