Facebook login through Jsoup

I tried to log in to my Facebook account with these lines, which I read from the answer to an already published question, but I can not log in anyway! I am looking for some tips to fix 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 do not want to use the Facebook API!

+3
java login facebook jsoup
Nov 08 '13 at 4:43
source share
2 answers

There are several more 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 do not forget about the referer parameter. Facebook may prohibit the use of a one-time token to log in to prevent Facebook API bypass.

+1
Nov 08 '13 at 12:45
source share
— -

Try this, works great 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(); } 
0
Apr 23 '18 at 15:19
source share



All Articles