我需要发布Facebook粉丝页面,我无法发布,直到我逐行调试代码

时间:2013-08-22 21:11:19

标签: asp.net facebook facebook-graph-api facebook-javascript-sdk

我通过我的网络应用程序在Facebook上发布,我面临的问题是,当调试代码行逐行消息在页面上发布但在单击函数上执行时它不会。 我无法理解这种行为。有人可以帮帮我吗?

protected void btnAddPostToPage_Click(object sender, EventArgs e)
    {
        var pageID = Session["SelectedPageID"] != null ? Session["SelectedPageID"].ToString() : string.Empty;
        if (string.IsNullOrEmpty(pageID)) { Response.Redirect("FBpageToCreateSC.aspx"); }

        string app_id = "";
        string app_secret = "";
        string scope = "publish_stream,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 = 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);




            client.Post(string.Concat("/PageId/feed"),new { message = "Message Text " + Guid.NewGuid().ToString().Substring(0,4) });
        }
    }
} 

0 个答案:

没有答案