Author Topic: Automating Facebook Login  (Read 1527 times)

0 Members and 1 Guest are viewing this topic.

arjunbahl

  • Guest
Automating Facebook Login
« on: January 01, 2016, 03:42:56 pm »
Firstly Happy New Year to all members! ;)

So i was trying to build a facebook api myself in python. I'm using Requests module, although everything seems easy but facebook some has coded a little messy trick somewhere in their home page.

The following parameters are necessary for anyone to login, which are sent in the form of POST data:
  • lsd
  • email
  • pass
  • default-persistence
  • timezone
  • lgndim
  • lgnrnd
  • lgnjs
  • locale
  • qsstamp

Now after my research i found that:
  • lgnjs: On reverse engineering i found this function in https://static.xx.fbcdn.net/rsrc.php/v2/yN/r/CY6jShTMyGt.js
    var s = i('lgnjs');
            if (s) {
                var t = Math.floor(Date.now() / 1000);
                s.value = t;
            }
    which is basically time.time() in python
  • lsd: it is found in the html file itself within hidden input fields of the login_form
  • Obviously email and pass is self explanatory
  • timezone and default_persistence is something that remains constant unless you travel a lot, so lets assume it to be constant
  • lgnrnd: It is present in the html form with the attribute "value" which can be very easily scraped
  • qsstamp and lgndim: These are the two parameters that are difficult to find, this where i'm stuck! :'(

All the above parameters are dynamically generated via Javascript on the client side.
Also it seems if you POST data without any of the above or with any wrong value except email and pass you get the error: "Please enable cookies in your browser"
Can anyone help me with qsstamp and lgndim?




NOTE:
Although it works on m.facebook.com as it doesn't require any of the above POST params.
« Last Edit: January 01, 2016, 04:00:29 pm by arjunbahl »

Offline aaanathan

  • /dev/null
  • *
  • Posts: 5
  • Cookies: -1
    • View Profile
Re: Automating Facebook Login
« Reply #1 on: January 15, 2016, 05:47:46 pm »
Hi,

A very happy new year to you Arjun.

I have tried this once before a year. A few points to note here.
Consider you are able to login automatically and wanted to fetch the friends list.

1. I hope you could have checked the source code once you logged in Facebook. Everything is JavaScript to generate a page.
2. Still site loads the content based on your scroll event.
3. So Requests module will not support JavaScript.
4. Please move to some headless browser like phantomjs casperjs or selenium web driver to automate web automation.

Hope this helps in some point.

Sent from my A0001 using Tapatalk