【问题标题】:Post On Facebook Page As Page Not As Admin User Using Facebook C# SDK使用 Facebook C# SDK 在 Facebook 页面上作为页面而不是管理员用户发布
【发布时间】:2011-07-11 01:12:06
【问题描述】:

我正在开发使用 Facebook C# SDK 管理 Facebook 上的粉丝页面的 C# 应用程序。我遇到了两个问题,一个与在墙上发布消息有关,另一个与在粉丝页面上创建事件有关。

是否可以在粉丝页面墙上发布消息作为粉丝页面而不是管理员用户?

我可以使用 Facebook C# SDK 以编程方式在粉丝页面(不是管理员,而是作为粉丝页面)上创建事件吗?

我浏览了其他 SDK 的一些其他教程,例如 Facebook PHP SDK。 PHP SDK 允许将事件创建为粉丝页面,但在 C# SDK 的情况下,创建事件不会给出任何结果。

【问题讨论】:

标签: facebook-c#-sdk


【解决方案1】:

好的,我刚刚遇到了同样的事情。出于我的目的,我授权一个应用程序作为粉丝页面发布到 FB 粉丝页面。所以我可以有多个用户可以访问应用程序,但不能访问粉丝页面,作为粉丝页面发布。它符合我的要求。

无论如何,这就是我使用 C# Facebook SDK Beta V5.0.9 的方法。 第一步,确保您尝试发帖的用户帐户能够在粉丝页面上发帖,并且已获得应用授权。

其中大部分内容与 VorTechS 帖子类似,只是对此进行了更多说明。

Dictionary<string,string> fbParams = new Dictionary<string,string>();
                fbParams["message"] = Title;
                fbParams["caption"] = string.Empty;
                fbParams["description"] = string.Empty;
                fbParams["req_perms"] = "publish_stream";
                fbParams["scope"] = "publish_stream";
                //Initialize Your Facebook Client in the manner that suits you, I did it by supplying a saved access token from a single users
                FacebookWebClient fbClient = new FacebookWebClient(<YOUR_ACCOUNT_ACCESS_TOKEN>);
                //Get the listing of accounts associated with the user
                dynamic fbAccounts = fbClient.Get("/me/accounts");

                //Loop over the accounts looking for the ID that matches your destination ID (Fan Page ID)
                foreach (dynamic account in fbAccounts.data) {
                    if (account.id == <DESTINATION_ID_OF_YOUR_FAN_PAGE>) {
                        //When you find it, grab the associated access token and put it in the Dictionary to pass in the FB Post, then break out.
                        fbParams["access_token"] = account.access_token;
                        break;
                    }
                }
                //Then pass your destination ID and target along with FB Post info. You're Done.
                dynamic publishedResponse = fbClient.Post("/" + <DESTINATION_ID_OF_YOUR_FAN_PAGE> + "/feed", fbParams);

【讨论】:

    【解决方案2】:

    要发布消息,您需要授予 manages_pages 权限,并使用“/me/accounts”的结果从粉丝页的帐户中获取访问令牌。

    这是我用来将消息本身发布到粉丝页面的方法:

                                var dicParams = new Dictionary<string, object>();
                            dicParams["message"] = stSmContentTitle;
                            dicParams["caption"] = string.Empty;
                            dicParams["description"] = string.Empty;
                            dicParams["name"] = smContent.CmeUrl;
                            dicParams["req_perms"] = "publish_stream";
                            dicParams["scope"] = "publish_stream";
    
                            // Get the access token of the posting user if we need to
                            if (destinationID != this.FacebookAccount.UserAccountId)
                            {
                                dicParams["access_token"] = this.getPostingUserAuthToken(destinationID);
                            }
                            publishResponse = this.FacebookConnection.Post("/" + destinationID + "/feed", dicParams);
    

    【讨论】:

    • @camainc - 首先确保您使用将用于墙贴的身份登录 Facebook。然后在浏览器中使用此网址:https://www.facebook.com/dialog/oauth?client_id=[APPID]&amp;redirect_uri=[YOUR SITE URL]&amp;scope=offline_access,publish_stream&amp;response_type=token。一旦您允许 FCBK 对话框,您将被重定向到您在上面的 [YOUR SITE URL] 部分中使用的 URL,并附加了令牌(请参阅浏览器的地址栏)。请注意此处的权限offline_access,这将确保您的令牌不会过期。
    【解决方案3】:

    我要感谢您的帖子,这真的很有帮助。对我来说,它仍然在我的 Facebook 页面上发布为我(而不是页面)。我认为这只是我获得令牌的方式。虽然,foreach 循环对我不起作用。所以,我这样做了:

    public void postFacebook(object sender, EventArgs e)
    {
        //You will get your "myAccessToken" at this adress:
        //https://www.facebook.com/dialog/oauth?client_id=<YOUR_APP_ID>&redirect_uri=<THE_PAGE_YOU_WILL_RECEIVE_YOUR_TOKEN_AT>&scope=offline_access,manage_pages,publish_stream&response_type=token
        string myAccessToken = "<IN_THE_RETURNED_URL_BELOW>";
        string myPageId = "<YOUR_FAN_PAGE_ID>";
    
        Dictionary<string,string> fbParams = new Dictionary<string,string>();
        fbParams["message"] = "Testing 1 2 test";
        fbParams["caption"] = string.Empty;
        fbParams["description"] = string.Empty;
        fbParams["req_perms"] = "publish_stream";
        fbParams["scope"] = "publish_stream";
        //Initialize Your Facebook Client in the manner that suits you, I did it by supplying a saved access token from a single users
        Facebook.FacebookAPI fbClient = new Facebook.FacebookAPI(myAccessToken);
        //Get the listing of accounts associated with the user
        var fbAccounts = fbClient.Get("/me/accounts");
    
        //Loop over the accounts looking for the ID that matches your destination ID (Fan Page ID)
        foreach (var account in fbAccounts.Dictionary["data"].Array)
        {
            if (account.Dictionary["id"].String == myPageId)
            {
                //When you find it, grab the associated access token and put it in the Dictionary to pass in the FB Post, then break out.
                fbParams["access_token"] = account.Dictionary["access_token"].String;
    
                //Update the Access token (to post as the page). If you don't it will post as YOUR personal name.
                fbClient.AccessToken = fbParams["access_token"];
                break;
            }
        }
    
    
    
        //Then pass your destination ID and target along with FB Post info. You're Done.
        dynamic publishedResponse = fbClient.Post("/" + myPageId + "/feed", fbParams);
    }
    

    顺便说一下,你需要这个sdk:SDK

    【讨论】:

      【解决方案4】:

      在 MVC4 和 C# SDK 中,这达到了我的目标

        [FacebookAuthorize("publish_stream")]
          public ActionResult PostNotification(FacebookContext context)
          {
              var dicParams = new Dictionary<string, object>();
              dicParams["message"] = "đang tập code cho facebook ~@@";
              dicParams["caption"] = "bbbbb";
              dicParams["description"] = "cccccc";
              dicParams["name"] = "http://www.facebook.com";
              dicParams["req_perms"] = "publish_stream";
              dicParams["scope"] = "publish_stream";
              string destinationID = context.UserId;
              context.Client.Post("/" + destinationID + "/feed", dicParams);
              return RedirectToAction("Index");
          }
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2014-07-16
        • 2013-03-25
        • 2013-09-21
        • 2011-03-01
        • 1970-01-01
        相关资源
        最近更新 更多