Wie die Anmeldung in Facebook programmatisch mit Java?

Ich versuche ein Java-Programm schreiben, dass automatisch log in Facebook.

Habe ich den code unten so weit, dass downloads home html-Seite in einen String, aber nicht wissen, wie Sie zum senden der E-Mail und Passwort zum einloggen in Facebook? Auch wird das Java-Programm müssen für den Umgang mit cookies zurückgegeben, eingeloggt bleiben?

public static void main(String[] args) throws Exception {
        URL url = new URL("http://www.facebook.com/");
        URLConnection yc = url.openConnection();
        BufferedReader in = new BufferedReader(new InputStreamReader(yc
                .getInputStream()));
        String inputLine;
        String allInput = "";

        while ((inputLine = in.readLine()) != null) {

            allInput += inputLine + "\r\n";
        }
        System.out.println(allInput);

        in.close();
    }

}

Update:

Ich habe versucht den folgenden code mithilfe von htmlUnit jedoch bekomme ich die folgende exception:

Exception in thread "main" com.gargoylesoftware.htmlunit.ElementNotFoundException:     elementName=[form] attributeName=[name] attributeValue=[login_form] at com.gargoylesoftware.htmlunit.html.HtmlPage.getFormByName(HtmlPage.java:588)

Jemand wissen, warum das so ist?

    final WebClient webClient = new WebClient();
    final HtmlPage page1 = webClient.getPage("http://www.facebook.com");
    final HtmlForm form = page1.getFormByName("login_form");

    final HtmlSubmitInput button = (HtmlSubmitInput) form.getInputsByValue("Login").get(0);
    final HtmlTextInput textField = form.getInputByName("email");
    textField.setValueAttribute("[email protected]");
    final HtmlTextInput textField2 = form.getInputByName("pass");
    textField2.setValueAttribute("ahhhh");
    final HtmlPage page2 = button.click();
Aber ich bin immer einige Ausnahmen wie Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/commons/httpclient/Protokoll/ProtocolSocketFactory. Sie können angeben, welche version von Htmlunit jar heruntergeladen werden-einfach, um sicherzugehen, dass ich das richtige getan

InformationsquelleAutor tree-hacker | 2010-02-17

Schreibe einen Kommentar