3

I tried to log into my Facebook account with these lines that I read from an answer to a question already posted, but I can't log in anyway! I looking for some tips to correct the code:

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: No i don't want to use Facebook APIs!

ashatte
  • 5,442
  • 8
  • 39
  • 50
Amanda
  • 49
  • 1
  • 7

2 Answers2

1

There are a bunch other parameters that are passed in the request:

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

And dont forget about referer parameter. Facebook may ganerate some sort of one-time token for login request to prevent bypassing of Facebook API.

vacuum
  • 2,273
  • 3
  • 20
  • 32
  • what are lgnjs and lgnrnd? – Amanda Nov 08 '13 at 13:06
  • 1
    @Amanda Not sure about `lgnjs` but I read on another post that `lgnrnd` is there to make it difficult for automated login. If you view the source of the Facebook login page, the value for `lgnrnd` changes with every refresh, whereas `lgnjs` just has a value of n for me. – ashatte Nov 08 '13 at 14:20
  • @ashatte, If I give all above parameters to JSOUP. Will I be able to Login? – Vishwajit R. Shinde Sep 10 '15 at 14:36
0

Try this, works fine for me:

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();
}