3

我尝试使用从已发布问题的答案中读取的这些行登录我的 Facebook 帐户,但无论如何我都无法登录!我正在寻找一些提示来更正代码:

Connection.Response res = Jsoup.connect("https://www.facebook.com/login.php")
    .data("email", "mymail", "pass", "mypas")
    .method(Method.POST)
    .execute();

    System.out.println(res.statusCode());
    Document doc = res.parse();
    String sessionId = res.cookie("SESSIONID");

PS:不,我不想使用 Facebook API!

4

2 回答 2

1

请求中传递了许多其他参数:

lsd:AVptuGRS
email:***
pass:***
default_persistent:0
timezone:-120
lgnrnd:043627_eQnN
lgnjs:1383914188
locale:en_US

并且不要忘记referer参数。Facebook 可能会为登录请求生成某种一次性令牌,以防止绕过 Facebook API。

于 2013-11-08T12:45:21.947 回答
0

试试这个,对我来说很好:

Response req;
try {
    String userAgent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/65.0.3325.181 Safari/537.36";

    req = Jsoup.connect("https://m.facebook.com/login/async/?refsrc=https%3A%2F%2Fm.facebook.com%2F&lwv=100")
        .userAgent(userAgent)
        .method(Method.POST).data("email", "YOUR_EMAIL").data("pass", "YOUR_PASSWORD")
        .followRedirects(true).execute();

    Document d = Jsoup.connect("https://m.facebook.com/profile.php?ref=bookmarks").userAgent(userAgent)
        .cookies(req.cookies()).get();

    System.out.println(d.body().text().toString());
} catch (Exception e) {
    e.printStackTrace();
}
于 2018-04-23T15:19:53.317 回答