Facebook整合“发生错误再试一次”?

时间:2013-04-18 09:41:18

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

我正在尝试将我的应用与Facebook连接。我在facebook上创建了应用程序,这是我的代码:

private void CheckAuthorization()
        {
            string app_id = "appID";
            string app_secret = "appSecret";
            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("/me/feed", new { message = "markhagan.me video tutorial" });
            }
        }

页面加载登录时弹出窗口显示。当我用创建facebook app的用户的电子邮件登录时,工作完美。但是每个其他不同的登录都会导致消息“发生错误,请稍后重试”。有人能告诉我我在哪里弄错了吗?

1 个答案:

答案 0 :(得分:0)

确保应用程序沙盒模式设置为“关闭”