0

こんにちは、Facebook 投稿フィード アプリケーションを使用しています。このアプリケーションは、Facebook ページからすべての新しい投稿を読み取り、sharepoint リストに保存します。以前、つまり、6 月より前に正常に機能し、fabebook からのすべての投稿が私の共有ポイント リストにフィードされました。しかし、最近では、Facebook 承認 URL からの応答を取得中にエラーがスローされます。何がうまくいかなかったのかわかりません。この問題を解決するための提案があれば、私を助けてください。以下にコード部分を追加しています。

private void btnSendToList_Click(object sender, EventArgs e)
    {
        try
        {
            if (ConfigurationSettings.AppSettings["fbClientID"] != null)
                strClientID = ConfigurationSettings.AppSettings["fbClientID"];

            if (ConfigurationSettings.AppSettings["fbRedirectURL"] != null)
                strURL = ConfigurationSettings.AppSettings["fbRedirectURL"];

            if (ConfigurationSettings.AppSettings["fbCltSecret"] != null)
                strCltSecret = ConfigurationSettings.AppSettings["fbCltSecret"];

            if (ConfigurationSettings.AppSettings["fbUserId"] != null)
                strUserId = ConfigurationSettings.AppSettings["fbUserId"];

            if (ConfigurationSettings.AppSettings["SPSiteURL"] != null)
                strSiteURL = ConfigurationSettings.AppSettings["SPSiteURL"];


            CookieCollection cookies = new CookieCollection();
            HttpWebRequest request = (HttpWebRequest)WebRequest.Create("https://www.facebook.com");
            request.UserAgent = "Mozilla/5.0 (Windows NT 6.1) AppleWebKit/535.2 (KHTML, like Gecko) Chrome/15.0.874.121 Safari/535.2";
            request.CookieContainer = new CookieContainer();
            request.CookieContainer.Add(cookies);
            //Get the response from the server and save the cookies from the first request..
            HttpWebResponse response = (HttpWebResponse)request.GetResponse();
            cookies = response.Cookies;

            string getUrl = "https://www.facebook.com/login.php?login_attempt=1";
            string postData = String.Format("email={0}&pass={1}", "testuser@gmail.com", "test123$"); // Masking credentials.
            getRequest = (HttpWebRequest)WebRequest.Create(getUrl);
            getRequest.CookieContainer = request.CookieContainer;
            getRequest.CookieContainer.Add(cookies);
            getRequest.Method = WebRequestMethods.Http.Post;
            getRequest.UserAgent = "Mozilla/5.0 (Windows NT 6.1) AppleWebKit/535.2 (KHTML, like Gecko) Chrome/15.0.874.121 Safari/535.2";
            getRequest.AllowWriteStreamBuffering = true;
            getRequest.ProtocolVersion = HttpVersion.Version11;
            getRequest.AllowAutoRedirect = true;
            getRequest.ContentType = "application/x-www-form-urlencoded";

            byteArray = Encoding.ASCII.GetBytes(postData);
            getRequest.ContentLength = byteArray.Length;
            newStream = getRequest.GetRequestStream(); //open connection
            newStream.Write(byteArray, 0, byteArray.Length); // Send the data.

            getResponse = (HttpWebResponse)getRequest.GetResponse();

            getRequest = (HttpWebRequest)WebRequest.Create(string.Format("https://graph.facebook.com/oauth/authorize?client_id={0}&redirect_uri={1}", strClientID, "http://www.facebook.com/connect/login_success.html"));
            getRequest.Method = WebRequestMethods.Http.Get;
            getRequest.CookieContainer = request.CookieContainer;
            getRequest.CookieContainer.Add(cookies);
            getRequest.UserAgent = "Mozilla/5.0 (Windows NT 6.1) AppleWebKit/535.2 (KHTML, like Gecko) Chrome/15.0.874.121 Safari/535.2";
            getRequest.AllowWriteStreamBuffering = true;
            //getRequest.ProtocolVersion = HttpVersion.Version11;
            getRequest.AllowAutoRedirect = true;
            getRequest.ContentType = "application/x-www-form-urlencoded";              

            getResponse = (HttpWebResponse)getRequest.GetResponse(); 

上記の行は、Process がタイムアウトしたように動作する WebExcepton をスローします。

            strAccessToken = getResponse.ResponseUri.Query;
            strAccessToken = strAccessToken.Replace("#_=_", "");
            strAccessToken = strAccessToken.Replace("?code=", "");

            newStream.Close();

            if (!string.IsNullOrEmpty(strAccessToken))
                strCode = strAccessToken;

            if (!string.IsNullOrEmpty(strCode) && !string.IsNullOrEmpty(strClientID) &&
                    !string.IsNullOrEmpty(strURL) && !string.IsNullOrEmpty(strCltSecret) &&
                            !string.IsNullOrEmpty(strUserId))
            {
                SaveToList();
            }
        }
        catch (Exception ex)
        {
            LogError(ex);
        }
    }
4

1 に答える 1