fbessez / Tinder

Official November 2019 Documentation for Tinder's API (wrapper included)
MIT License
838 stars 198 forks source link

BadRequestKeyError when attempting to retrieve fb access token #131

Open Klexus1 opened 3 years ago

Klexus1 commented 3 years ago

Error: werkzeug.exceptions.BadRequestKeyError: 400 Bad Request: The browser (or proxy) sent a request that this server could not understand.

To replicate the behaviour: Clone the repository (as of 20 . 3. 2021) Install requirements (with Werkzeug==0.16.1) Enter your credentials in tinder_config_ex.py

Run.

Full traceback:

Traceback (most recent call last):
  File "C:/test-projekty/tinder-api/Tinder/tinder_config_ex.py", line 5, in <module>
    fb_access_token = fb_auth_token.get_fb_access_token(fb_username, fb_password)
  File "C:\test-projekty\tinder-api\Tinder\fb_auth_token.py", line 16, in get_fb_access_token
    f["pass"] = password
  File "C:\test-projekty\tinder-api\Tinder\tinderenv\lib\site-packages\robobrowser\forms\form.py", line 216, in __setitem__
    self.fields[key].value = value
  File "C:\test-projekty\tinder-api\Tinder\tinderenv\lib\site-packages\werkzeug\datastructures.py", line 795, in __getitem__
    raise exceptions.BadRequestKeyError(key)
werkzeug.exceptions.BadRequestKeyError: 400 Bad Request: The browser (or proxy) sent a request that this server could not understand.

Process finished with exit code 1

The program fails ons.open(FB_AUTH) line 14, fb_auth_token.py

Note: the FB_AUTH is a valid url. Tried in browser and works as expected.

aspirez4 commented 3 years ago

Change get_fb_access_token function to this

def get_fb_access_token(email, password):
    s = robobrowser.RoboBrowser(user_agent=MOBILE_USER_AGENT, parser="lxml")
    s.open(FB_AUTH)
    f = s.get_form()
    s.submit_form(f)
    f = s.get_form()
    f["pass"] = password
    f["email"] = email
    s.submit_form(f)
    f = s.get_form()
    try:
        s.submit_form(f, submit=f.submit_fields['__CONFIRM__'])
        access_token = re.search(
            r"access_token=([\w\d]+)", s.response.content.decode()).groups()[0]
        return access_token
    except requests.exceptions.InvalidSchema as browserAddress:
        access_token = re.search(
            r"access_token=([\w\d]+)",str(browserAddress)).groups()[0]
        return access_token
    except Exception as ex:
        print("access token could not be retrieved. Check your username and password.")
        print("Official error: %s" % ex)
        return {"error": "access token could not be retrieved. Check your username and password."}
Edvards79 commented 3 years ago

Change MOBILE_USER_AGENT variable to Mozilla/5.0 (Linux; U; Android 4.4.2; en-us; SCH-I535 Build/KOT49H) AppleWebKit/534.30 (KHTML, like Gecko) Version/4.0 Mobile Safari/534.30. The old one seems to be outdated for facebook and it shows error message instead of the login form.

jsdjsd commented 2 years ago

Hello all, Does this still work for you ? I think something changed but im not able to find a fix... Im using at the moment the same function as you and the following variables :

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&display=touch&state=%7B%22challenge%22%3A%22IUUkEUqIGud332lfu%252BMJhxL4Wlc%253D%22%2C%220_auth_logger_id%22%3A%2230F06532-A1B9-4B10-BB28-B29956C71AB1%22%2C%22com.facebook.sdk_client_state%22%3Atrue%2C%223_method%22%3A%22sfvc_auth%22%7D&scope=user_birthday%2Cuser_photos%2Cuser_education_history%2Cemail%2Cuser_relationship_details%2Cuser_friends%2Cuser_work_history%2Cuser_likes&response_type=token%2Csigned_request&default_audience=friends&return_scopes=true&auth_type=rerequest&client_id=464891386855067&ret=login&sdk=ios&logger_id=30F06532-A1B9-4B10-BB28-B29956C71AB1&ext=1470840777&hash=AeZqkIcf-NEW6vBd"

NorrisPau commented 1 year ago

Did you find a fix after all @jsdjsd ?