Source Code for Me (s-c.me)

Allows you to paste souce code to blogs! Adapted for Twitter! Here is Search Form in case you missed your code.
Code:
Selected Language:
Show Linenumbers:
Short link for Twitter:
HTML:

HTML view:

Copy Source | Copy HTML
  1. /// [Test]
  2. /// public void Import()
  3. /// {
  4. /// Facebook b2f = new Facebook();
  5. /// b2f.UpdateRss(new UserAccaunt("login", "pass"), "17404430442");
  6. /// }
  7. /// </example>
  8. [BlogServiceAPI(Description = "Facebook", Link = "http://facebook.com")]
  9. public class Facebook : WebInterface
  10. {
  11.     HttpWebRequest myHttpWebRequest;
  12.     HttpWebResponse myHttpWebResponse;
  13.  
  14.     public Boolean UpdateRss(UserAccaunt user,string rssid)
  15.     {
  16.         if (LogInto(user))
  17.         {
  18.             try
  19.             {
  20.  
  21.  
  22.                 myHttpWebRequest =
  23.                     MakeRequest("http://www.facebook.com/?ref=home");
  24.                 myHttpWebRequest.Method = "GET"; // Ð¼ÐµÑ‚од GET
  25.                 myHttpWebRequest.Referer = "http://facebook.com";
  26.                 myHttpWebRequest.AllowAutoRedirect = false;
  27.                 //получаем Ð¾Ñ‚вет Ð¸ ÐµÐ³Ð¾ Ñ€Ð°Ð·Ð±Ð¸Ñ€Ð°ÐµÐ¼...
  28.                 myHttpWebResponse = (HttpWebResponse) myHttpWebRequest.GetResponse();
  29.                 string result = new StreamReader(myHttpWebResponse.GetResponseStream(), Encoding.UTF8).ReadToEnd();
  30.                 myHttpWebResponse.Close();
  31.                 //
  32.                 string post_form_id =
  33.                     new Regex(@"name\W+post_form_id\W+value\W+(\w+)\W",
                                      RegexOptions.Singleline | RegexOptions.IgnoreCase).Match(result).Groups[1].Value;


                        ////////////////////////
                        ///запрос Ð½Ð° Ð¾Ð±Ð½Ð¾Ð²Ð»ÐµÐ½Ð¸Ðµ
                        /// ////////////////////
                        int i = 1;
                        do
                        {
                            myHttpWebRequest = MakeRequest("http://www.facebook.com/ajax/feedcrawl.php?__a=1");
  34.                     myHttpWebRequest.Method = "POST"; // Ð¼ÐµÑ‚од GET
  35.                     myHttpWebRequest.Referer = "http://facebook.com";
  36.                     myHttpWebRequest.AllowAutoRedirect = false;
  37.  
  38.                     myHttpWebRequest.ContentType = "application/x-www-form-urlencoded";
  39.                     // Ð¿ÐµÑ€ÐµÐ´Ð°ÐµÐ¼ Ð¿Ð°Ñ€Ð°Ð¼ÐµÑ‚ры
  40.                     //id="post_form_id" name="post_form_id" value="0ae76ef7e6077035e571580cefa9fc8d"
  41.                     string sQueryString =
  42.                         String.Format(
                                    "id={0}&action=update_story&post_form_id={1}&fb_dtsg=I624T&post_form_id_source=AsyncRequest",
                                    rssid, post_form_id
                                    );
  43.                     byte[] byteArr = Encoding.UTF8.GetBytes(sQueryString);
  44.                     myHttpWebRequest.ContentLength = byteArr.Length;
  45.                     myHttpWebRequest.GetRequestStream().Write(byteArr, 0, byteArr.Length);
  46.  
  47.                     //id=17404430442&action=update_story&post_form_id=0ae76ef7e6077035e571580cefa9fc8d&fb_dtsg=I624T&post_form_id_source=AsyncRequest
  48.                     myHttpWebResponse = (HttpWebResponse) myHttpWebRequest.GetResponse();
  49.                     result = new StreamReader(myHttpWebResponse.GetResponseStream(), Encoding.UTF8).ReadToEnd();
  50.                     myHttpWebResponse.Close();
  51.                     if (i++ > 10) return false;
  52.                 } while (result.Contains("url you entered is not valid"));
  53.                 return true;
  54.             }catch(Exception e1)
  55.             {
  56.                 Debug.WriteLine(e1.Message);
  57.             }
  58.         }
  59.         return false;
  60.     }
  61.  
  62.     public Boolean LogInto(UserAccaunt user)
  63.     {
  64.         try
  65.         {
  66.             myHttpWebRequest = MakeRequest("https://login.facebook.com/");
  67.             myHttpWebRequest.Method = "GET"; // Ð¼ÐµÑ‚од GET
  68.             myHttpWebRequest.Referer = "http://facebook.com";
  69.             myHttpWebRequest.AllowAutoRedirect = false;
  70.             //получаем Ð¾Ñ‚вет Ð¸ ÐµÐ³Ð¾ Ñ€Ð°Ð·Ð±Ð¸Ñ€Ð°ÐµÐ¼...
  71.             myHttpWebResponse = (HttpWebResponse) myHttpWebRequest.GetResponse();
  72.             sCookie = CookieParse(myHttpWebResponse.Headers[HttpResponseHeader.SetCookie]);
  73.             sCookie += "; reg_fb_ref=http%3A%2F%2Fwww.facebook.com%2F";
  74.             //string result = new StreamReader(myHttpWebResponse.GetResponseStream(), Encoding.UTF8).ReadToEnd();
  75.             myHttpWebResponse.Close();
  76.  
  77.             ///а Ñ‚еперь ÑÐ°Ð¼ Ð·Ð°Ð¿Ñ€Ð¾Ñ
  78.             myHttpWebRequest = MakeRequest("https://login.facebook.com/login.php?login_attempt=1");
  79.             myHttpWebRequest.Method = "POST"; // Ð¼ÐµÑ‚од GET
  80.             myHttpWebRequest.Referer = "http://facebook.com";
  81.             myHttpWebRequest.AllowAutoRedirect = false;
  82.             //charset_test=%E2%82%AC%2C%C2%B4%2C%E2%82%AC%2C%C2%B4%2C%E6%B0%B4%2C%D0%94%2C%D0%84&locale=en_US&email=onestory%40yandex.ru&pass=qQwklopq&charset_test=%E2%82%AC%2C%C2%B4%2C%E2%82%AC%2C%C2%B4%2C%E6%B0%B4%2C%D0%94%2C%D0%84&lsd=NT7ew
  83.             myHttpWebRequest.ContentType = "application/x-www-form-urlencoded";
  84.             // Ð¿ÐµÑ€ÐµÐ´Ð°ÐµÐ¼ Ð¿Ð°Ñ€Ð°Ð¼ÐµÑ‚ры
  85.             string sQueryString =
  86.                 String.Format(
                            "charset_test=%E2%82%AC%2C%C2%B4%2C%E2%82%AC%2C%C2%B4%2C%E6%B0%B4%2C%D0%94%2C%D0%84&locale=en_US&email={0}&pass={1}&charset_test=%E2%82%AC%2C%C2%B4%2C%E2%82%AC%2C%C2%B4%2C%E6%B0%B4%2C%D0%94%2C%D0%84&lsd=NT7ew",
                            HttpUtility.UrlEncode(user.username),
  87.                     HttpUtility.UrlEncode(user.password)
  88.                     );
  89.             byte[] byteArr = Encoding.UTF8.GetBytes(sQueryString);
  90.             myHttpWebRequest.ContentLength = byteArr.Length;
  91.             myHttpWebRequest.GetRequestStream().Write(byteArr, 0, byteArr.Length);
  92.  
  93.             //получаем Ð¾Ñ‚вет Ð¸ ÐµÐ³Ð¾ Ñ€Ð°Ð·Ð±Ð¸Ñ€Ð°ÐµÐ¼...
  94.             myHttpWebResponse = (HttpWebResponse) myHttpWebRequest.GetResponse();
  95.             //result = new StreamReader(myHttpWebResponse.GetResponseStream(), Encoding.UTF8).ReadToEnd();
  96.             sCookie = CookieParse(myHttpWebResponse.Headers[HttpResponseHeader.SetCookie]);
  97.             //
  98.             myHttpWebResponse.Close();
  99.             return sCookie.Contains("c_user");
  100.         }catch
  101.         {
  102.             return false;
  103.         }
  104.     }
  105. }




Based on Manoli.Net's CodeFormatter. Made by Topbot (c) 2008-2012