2013-04-18 35 views
1

我正嘗試將我的應用程序與Facebook連接。我在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應用程序的用戶的電子郵件登錄時,永久完美。但是每隔一次不同的登錄都會導致消息「以後再次發生錯誤」。有人能告訴我我在哪裏犯錯嗎?

回答

0

確保應用程序沙盒模式設置爲「關」

+0

Thx,即解決了我的問題。 :) –

相關問題