Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7490499
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T15:37:12+00:00 2026-05-29T15:37:12+00:00

I am trying to build a desktop app to use facebook api and get

  • 0

I am trying to build a desktop app to use facebook api and get data from friends.
Anyways I am stuck in the log in stage.
I have used some advice and made the log in to facebook with WebBrowser. It works great.
I am stuck at trying to make it give me status = Failed or success

I tried doing it like this at the end of the button_1 method

if (!w.DocumentText.Contains(@"<div class=""linkWrap noCount"">Messages</div>"))
    {
        w.Navigate(@"http://www.facebook.com/login.php");
        MessageBox.Show("Login error. Wrong username or password!");
    }

    else
    {
       MessageBox.Show("Logged in successfully");

    }

the < div class=””linkWrap noCount””>Messages< /div> is only shown while logged in so thats why I use it to see if a user is logged in

but the problem is it always gives me an error (wrong user and pass) becasue it reads it before the browser finishes to navigate to the page. I tried threads and thread sleep and even timers but it doesnt seem to work

an ideas?

here is the code:

private void button1_Click(object sender, EventArgs e)
    {
        Thread thread = new Thread(new ThreadStart(WorkThreadFunction));
        thread.Start();

         string email = textBox1.Text;
    string password = textBox2.Text;

    // create a new browser
    WebBrowser w = new WebBrowser();
    w.Dock = DockStyle.Fill;
    this.Controls.Add(w); // you may add the controll to your windows forms if  you want to see what is going on
    // latter you may not chose to add the browser or you can even set it to invisible... 


    // navigate to facebook
    w.Navigate(@"http://www.facebook.com/login.php");

    // wait a little
    for (int i = 0; i < 100; i++)
    {
        System.Threading.Thread.Sleep(10);
        System.Windows.Forms.Application.DoEvents();
    }


    HtmlElement temp=null;

    // while we find an element by id named email
    while (temp == null)
    {
        temp = w.Document.GetElementById("email");
        System.Threading.Thread.Sleep(10);
        System.Windows.Forms.Application.DoEvents();
    }

    // once we find it place the value
    temp.SetAttribute("value", email);


    temp = null;
    // wiat till element with id pass exists
    while (temp == null)
    {
        temp = w.Document.GetElementById("pass");
        System.Threading.Thread.Sleep(10);
        System.Windows.Forms.Application.DoEvents();
    }
    // once it exist set its value equal to passowrd
    temp.SetAttribute("value", password);

    // if you already found the last fields the button should also be there...

    var inputs = w.Document.GetElementsByTagName("input");

    int counter = 0;
    bool enableClick = false;

    // iterate through all the inputs in the document
    foreach (HtmlElement btn in inputs)
    {

        try
        {
            var att = btn.GetAttribute("tabindex");
            var name = btn.GetAttribute("id");

            if (enableClick)// button to submit always has a differnt id. it should be after password textbox
            {
                btn.InvokeMember("click");
                counter++;
            }

            if (name.ToUpper().Contains("PASS") || att=="4") 
            {
                enableClick = true;  // button should be next to the password input                    
            }

            // try a max of 5 times
            if (counter > 5)
            {
                break;

            }
        }
        catch
        {


        }


                }






    }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T15:37:16+00:00Added an answer on May 29, 2026 at 3:37 pm

    Checkout the facebook-sharp SDK for Windows forms:

    https://github.com/facebook-csharp-sdk/facebook-winforms

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to build a desktop PHP app. <!DOCTYPE HTML> <html> <body> <script
I'm trying build a method which returns the shortest path from one node to
I am trying to build my Android project with Ant. Whenever I use Eclipse
I'm trying to extract new revisions of Chromium.app from their snapshots, and I can
i am trying to build a desktop application that requires no run time, therefore
I'm trying to build a small Java app for connecting to an application called
I am trying to build a simple desktop application where the user enters the
I am trying to build remote desktop application using java. For that what I
I'm trying to build a simple app for parenting control in .NET. The main
I am trying to build an Adobe AIR app that runs on two monitors

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.