Created
October 3, 2015 19:46
-
-
Save UndergroundLabs/fad38205068ffb904685 to your computer and use it in GitHub Desktop.
Facebook Python Login Script
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/home/drspock/scripts/FBInvite/bin/python | |
import argparse | |
import requests | |
import pyquery | |
def login(session, email, password): | |
''' | |
Attempt to login to Facebook. Returns user ID, xs token and | |
fb_dtsg token. All 3 are required to make requests to | |
Facebook endpoints as a logged in user. Returns False if | |
login failed. | |
''' | |
# Navigate to Facebook's homepage to load Facebook's cookies. | |
response = session.get('https://m.facebook.com') | |
# Attempt to login to Facebook | |
response = session.post('https://m.facebook.com/login.php', data={ | |
'email': email, | |
'pass': password | |
}, allow_redirects=False) | |
# If c_user cookie is present, login was successful | |
if 'c_user' in response.cookies: | |
# Make a request to homepage to get fb_dtsg token | |
homepage_resp = session.get('https://m.facebook.com/home.php') | |
dom = pyquery.PyQuery(homepage_resp.text.encode('utf8')) | |
fb_dtsg = dom('input[name="fb_dtsg"]').val() | |
return fb_dtsg, response.cookies['c_user'], response.cookies['xs'] | |
else: | |
return False | |
if __name__ == "__main__": | |
parser = argparse.ArgumentParser(description='Login to Facebook') | |
parser.add_argument('email', help='Email address') | |
parser.add_argument('password', help='Login password') | |
args = parser.parse_args() | |
session = requests.session() | |
session.headers.update({ | |
'User-Agent': 'Mozilla/5.0 (X11; Linux i686; rv:39.0) Gecko/20100101 Firefox/39.0' | |
}) | |
fb_dtsg, user_id, xs = login(session, args.email, args.password) | |
if user_id: | |
print '{0}:{1}:{2}'.format(fb_dtsg, user_id, xs) | |
else: | |
print 'Login Failed' |
Working 2 april 2019. Thanks!
it doesn't work!!!!how it works with you ,please.??
hi how you doing brother
…On Fri, Nov 24, 2023, 20:02 emanalqudah ***@***.***> wrote:
***@***.**** commented on this gist.
------------------------------
Working 2 april 2019. Thanks!
it doesn't work!!!!how it works with you ,please.??
—
Reply to this email directly, view it on GitHub
<https://gist.github.com/UndergroundLabs/fad38205068ffb904685#gistcomment-4771798>
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/ARDJ7JUXITCUQJLDNA6BZLLYGDVM5BFKMF2HI4TJMJ2XIZLTSKBKK5TBNR2WLJDHNFZXJJDOMFWWLK3UNBZGKYLEL52HS4DFQKSXMYLMOVS2I5DSOVS2I3TBNVS3W5DIOJSWCZC7OBQXE5DJMNUXAYLOORPWCY3UNF3GS5DZVRZXKYTKMVRXIX3UPFYGLK2HNFZXIQ3PNVWWK3TUUZ2G64DJMNZZDAVEOR4XAZNEM5UXG5FFOZQWY5LFVAZDMOBWGI2DOMNHORZGSZ3HMVZKMY3SMVQXIZI>
.
You are receiving this email because you commented on the thread.
Triage notifications on the go with GitHub Mobile for iOS
<https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675>
or Android
<https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub>
.
File "C:\Users\Admin\Dev\Python\PyProject\fb-login.py", line 57, in
fb_dtsg, user_id, xs = login(session, args.email, args.password)
^^^^^^^^^^^^^^^^^^^^
TypeError: cannot unpack non-iterable bool object
=====================================================
This Might Be A Parsing Error Due To {and} in user password?
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
error: the following arguments are required: email, password
i am trying to put username and password but it gives error