• 11-07-2010, 19:58:34
    #1
    Merhabalar ;

    Ben HttpWebRequest ile facebook'a bağlanıp ordan mesajlarıma bakacak bir program yapmaya çalışıyorum. Bağlanabiliyorum ve bakabiliyorum. Sorun şu her kontrolde yeniden giriş yapıyorum tek bir sefer giriş yapıp 5 snde bir kontrol etmek istiyorum ama olmuyor kodları yazayım, bakrsanız sevinirim

       public partial class Form1 : Form
        {
            HttpWebRequest myRequest =
                  (HttpWebRequest)WebRequest.Create("http://m.facebook.com/login.php?http");
                
            
            public Form1()
            {
                InitializeComponent();
            }
    
            public int FacebookLogin()
            {
    
                string strMail = "email";
                string strPass = "sifre";
                ASCIIEncoding encoding = new ASCIIEncoding();
                string postData = "email=" + strMail;
                postData += ("&pass=" + strPass);
                byte[] data = encoding.GetBytes(postData);
    
                // Web Request
                myRequest.Method = "POST";
                myRequest.ContentType = "application/x-www-form-urlencoded";
                myRequest.ContentLength = data.Length;
                Stream newStream = myRequest.GetRequestStream();
    
                // Send the data.
                newStream.Write(data, 0, data.Length);
                newStream.Close();
    
                return 0;
            }
    
            public int FacebookKontrol()
            {
                string html = string.Empty;
                using (HttpWebResponse resp = (HttpWebResponse)myRequest.GetResponse())
                {
                    bool isSuccess = (int)resp.StatusCode < 299 && (int)resp.StatusCode >= 200;
                    if (isSuccess)
                    {
                        using (StreamReader reader = new StreamReader(resp.GetResponseStream()))
                        {
                            html = reader.ReadToEnd();
                        }
                    }
                }
                string str = html;
                int idx;
    
    
                idx = str.IndexOf("Gelen Kutusu (1)");
                if (idx > 0)
                    MessageBox.Show("Mesaj VAR!");
                return 0;
            }
    
            private void Form1_Load(object sender, EventArgs e)
            {
                FacebookLogin();
            }
    
            private void timer1_Tick(object sender, EventArgs e)
            {
                FacebookKontrol();
            }
        }
  • 23-07-2013, 18:22:33
    #2
    Cookie yüzünden her seferinde giriş yapılmasını istiyor sanırım. Mantık olarak cookie'leri bir txt dosyasında tutup aynı browser gibi oradan okumanız gerekiyor. WebRequest kütüphanesi için cookie kullanımı olarak araştırma yapmanızı tavsiye ediyorum.
  • 23-07-2013, 19:34:46
    #3
    Cassini nin dediği gibi cookie ile çözülebilr. ancak biraz daha profesyonel bir yöntemle bu işi yapmak gerek. facebook api !! https://developers.facebook.com/
  • 23-07-2013, 20:11:18
    #4
    Kimlik doğrulama veya yönetimden onay bekliyor.
    Ertan + 1, API kullan. Bu şekilde tonla kod yazarsın sorunlarını çözebilmek için.