【问题标题】:how to post on directly at facebook page using C# not at visitor post?如何使用 C# 直接在 Facebook 页面上发布,而不是在访客帖子上?
【发布时间】:2016-08-25 09:34:45
【问题描述】:

我推荐了这篇文章 how to post to facebook page wall from .NET 但它可以在 Facebook 页面上作为访客帖子发布。 我想发布页面时间线而不是访客帖子,我是这个页面和应用程序的管理员。 请给出解决方案。

在我的代码中

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Facebook;
using System.Dynamic;

public partial class facebook : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        authontication();
    }
    private void authontication()
    {
        string app_id = "**********************";
        string app_secret = "###################################";


        string scope = "publish_actions,manage_pages";

        if (Request["code"] == null)
        {
            Response.Redirect(string.Format(
                "https://graph.facebook.com/oauth/authorize?client_id={0}&redirect_uri={1}&scope={2}",
                app_id, Request.Url.AbsoluteUri, scope));
        }
        else
        {
            Dictionary<string, string> tokens = new Dictionary<string, string>();

            string url = string.Format("https://graph.facebook.com/oauth/access_token?client_id={0}&redirect_uri={1}&scope={2}&code={3}&client_secret={4}",
            app_id, Request.Url.AbsoluteUri, scope, Request["code"].ToString(), app_secret);

            HttpWebRequest request = System.Net.WebRequest.Create(url) as HttpWebRequest;

            using (HttpWebResponse response = request.GetResponse() as HttpWebResponse)
            {
                StreamReader reader = new StreamReader(response.GetResponseStream());
                string vals = reader.ReadToEnd();

                foreach (string token in vals.Split('&'))
                {
                    //meh.aspx?token1=steve&token2=jake&...
                    tokens.Add(token.Substring(0, token.IndexOf("=")),
                        token.Substring(token.IndexOf("=") + 1, token.Length - token.IndexOf("=") - 1));
                }
            }
            string access_token = tokens["access_token"];
            var client = new FacebookClient(access_token);

            //dynamic parameters = new ExpandoObject();
            string name = "sudhanshu";

            name += " new data";

            client.Post("/1168908853153698/feed", new { message = "My first appProduct "+name+" ." });



        }

    }

}

【问题讨论】:

  • 使用页面令牌,而不是用户令牌。
  • 我已经在使用页面令牌了。
  • 我在您的代码中的任何地方都没有看到,看起来您只是在使用用户令牌。看看我的回答。
  • 对不起先生,我听不懂你想说什么

标签: c# asp.net facebook facebook-graph-api facebook-c#-sdk


【解决方案1】:

您需要使用页面令牌,而不是用户令牌。通过调试确保它确实是一个页面令牌:https://developers.facebook.com/tools/debug/accesstoken/

另外,publish_actions 是错误的主页发布权限,您需要使用publish_pages

附加信息:

【讨论】:

  • 我使用了 publish_pages 方法,但仍然在访问者帖子上发布
  • 那么您没有使用页面令牌。确保您知道用户和页面令牌之间的区别并查看链接。
  • 感谢您的帮助,我现在可以直接在 Facebook 页面上发帖了。
  • 先生但是需要更多帮助如何动态获取页面访问令牌??
  • “动态”是什么意思? jsut 使用扩展页面令牌。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-07-11
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多