-
Notifications
You must be signed in to change notification settings - Fork 0
/
fb_auth_token.py
38 lines (33 loc) · 1.64 KB
/
fb_auth_token.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import re
import robobrowser
import requests
MOBILE_USER_AGENT = "Tinder/7.5.3 (iPhone; iOS 10.3.2; Scale/2.00)"
FB_AUTH = 'https://www.facebook.com/v2.6/dialog/oauth?redirect_uri=fb464891386855067%3A%2F%2Fauthorize%2F&scope=user_birthday%2Cuser_photos%2Cuser_education_history%2Cemail%2Cuser_relationship_details%2Cuser_friends%2Cuser_work_history%2Cuser_likes&response_type=token%2Csigned_request&client_id=464891386855067&ret=login&fallback_redirect_uri=221e1158-f2e9-1452-1a05-8983f99f7d6e&ext=1556057433&hash=Aea6jWwMP_tDMQ9y'
def get_access_token(email, password):
s = robobrowser.RoboBrowser(user_agent=MOBILE_USER_AGENT, parser="lxml")
s.open(FB_AUTH)
## submit login form
f = s.get_form()
f["pass"] = password
f["email"] = email
s.submit_form(f)
## click the 'ok' button on the dialog informing you that you have already authenticated with the Tinder app
f = s.get_form()
try:
s.submit_form(f, submit=f.submit_fields['__CONFIRM__'])
#print(s.response.content.decode())
access_token = re.search(
r"access_token=([\w\d]+)", s.response.content.decode()).groups()[0]
except requests.exceptions.InvalidSchema as browserAddress:
access_token = re.search(
r"access_token=([\w\d]+)", str(browserAddress)).groups()[0]
return(access_token)
except:
return None
def get_fb_id(access_token):
if "error" in access_token:
return {"error": "access token could not be retrieved"}
"""Gets facebook ID from access token"""
req = requests.get(
'https://graph.facebook.com/me?access_token=' + access_token)
return req.json()["id"]