如何使用facebook csharp sdk代表Facebook应用授权用户

在授权用户的同时获取错误....在这里输入图片描述

这是我的代码。

public partial class Facebook:System.Web.UI.Page {protected void Page_Load(object sender,EventArgs e){if(Request [“code”]!= null && Page.IsPostBack){checkauthorization(); }}

    protected void btnpost_Click(object sender, EventArgs e)
    {
        checkauthorization();
    }

    public void checkauthorization()
    {
        string app_id = "appid";
        string app_secret = "app secret";
        string scope = "publish_stream,manage_pages";

        if (Request["code"] == null)
        {
            Response.Redirect(string.Format("http://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("http://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('&'))
                {
                    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("/me/feed/", new { message = txtmsg.Text.Trim() });
        }

    }
}
链接地址: http://www.djcxy.com/p/43817.html

上一篇: how to authorize a user on behalf of facebook app using facebook csharp sdk

下一篇: assigning an id to a programmed textbox in asp.net