@@ 4,6 4,7 @@ import stat
import json
import datetime
import requests
+import cookielib
from . import constants
from .facebook import FacebookAuthRequest
@@ 51,11 52,21 @@ def load_api_from_file(fname=constants.D
return api.API(auth_handler=auth)
-def get_tinder_access_token(username, password):
+def get_tinder_access_token(username=None, password=None, cookie_file=None):
''' Helper to login to your FB account and authorize
the Tinder App to get an access token that will work
with the Tinder API.
'''
+ if cookie_file is not None:
+ use_cookies = cookielib.LWPCookieJar(
+ filename=os.path.expanduser(cookie_file),
+ )
+ try:
+ use_cookies.load()
+ except IOError:
+ # Cookie file doesn't exist yet.
+ pass
+
fb_url = ('https://www.facebook.com/dialog/oauth?client_id=464891386855067'
'&redirect_uri=https://www.facebook.com/connect/login_success.'
'html&scope=basic_info,email,public_profile,user_about_me,'
@@ 63,6 74,9 @@ def get_tinder_access_token(username, pa
'user_friends,user_interests,user_likes,user_location,'
'user_photos,user_relationship_details&response_type=token')
req = FacebookAuthRequest(username=username, password=password)
+ if cookie_file is not None:
+ req.session.cookies = use_cookies
+
response = req.authorized_request(url=fb_url)
if response.status_code != 200:
raise ValueError('Error logging in {0}'.format(response.content))
@@ 71,4 85,7 @@ def get_tinder_access_token(username, pa
res = re.search(r'.*access_token=(\w+)\&.*', location)
if not res:
raise ValueError('Unable to get access key {0}'.format(location))
+
+ if cookie_file is not None:
+ req.session.cookies.save()
return res.groups()[0]