Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to get Facebook Access Token and Facebook ID #171

Open
gragragrao opened this issue Jul 29, 2017 · 13 comments
Open

How to get Facebook Access Token and Facebook ID #171

gragragrao opened this issue Jul 29, 2017 · 13 comments

Comments

@gragragrao
Copy link

Hi, sorry to repeat an previously asked question, but I can't pass the facebook authentication; following error always occurs.

requests.exceptions.SSLError: ("bad handshake: Error([('SSL routines', 'ssl3_get_server_certificate', 'certificate verify failed')],)",)

I want to know the detail way to get facebook id and facebook access token.

Anything will be helpful.

@gragragrao
Copy link
Author

Is Tinder to blame for ssl error??
I thought that the ssl certification sent from tinder api is not correct and this cause my error.

any idea?

@pkillnine
Copy link

pkillnine commented Aug 16, 2017

@gragragrao I have a script used to get the access token. It requires Robobrowser.

import robobrowser

MOBILE_USER_AGENT = r"Mozilla/5.0 (Linux; U; en-gb; KFTHWI Build/JDQ39) AppleWebKit/535.19 (KHTML, like Gecko) Silk/3.16 Safari/535.19"
FB_AUTH = "https://m.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"

def get_access_token(email, password):
    s = robobrowser.RoboBrowser(user_agent=MOBILE_USER_AGENT, parser="lxml")
    s.open(FB_AUTH)
    f = s.get_form()
    f["pass"] = password
    f["email"] = email
    s.submit_form(f)
    f = s.get_form()
    if f.submit_fields.get('__CONFIRM__'):
        s.submit_form(f, submit=f.submit_fields['__CONFIRM__'])
    else:
        raise Exception("Couldn't find the continue button. Maybe you supplied the wrong login credentials? Or maybe Facebook is asking a security question?")
    access_token = re.search(r"access_token=([\w\d]+)", s.response.content.decode()).groups()[0]
    return access_token

It's been a while since I last used it so it may no longer work.

@jakubLangr
Copy link

Does this still work?

@robertmielewczyk
Copy link

robertmielewczyk commented Oct 18, 2018

It works if you run pkillnine code, but you also have to add "import re" and
get_access_token("your@email", "password"):
and instead of return use print(access_token)

so correct code should look like this (2018 October):

import robobrowser
import re

MOBILE_USER_AGENT = r"Mozilla/5.0 (Linux; U; en-gb; KFTHWI Build/JDQ39) AppleWebKit/535.19 (KHTML, like Gecko) Silk/3.16 Safari/535.19"
FB_AUTH = "https://m.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"

def get_access_token(email, password):
    s = robobrowser.RoboBrowser(user_agent=MOBILE_USER_AGENT, parser="lxml")
    s.open(FB_AUTH)
    f = s.get_form()
    f["pass"] = password
    f["email"] = email
    s.submit_form(f)
    f = s.get_form()
    if f.submit_fields.get('__CONFIRM__'):
        s.submit_form(f, submit=f.submit_fields['__CONFIRM__'])
    else:
        raise Exception("Couldn't find the continue button. Maybe you supplied the wrong login credentials? Or maybe Facebook is asking a security question?")
    access_token = re.search(r"access_token=([\w\d]+)", s.response.content.decode()).groups()[0]
    return access_token
    
get_access_token("yourFB@email", "yourFB_password") #This is not really safe as you will have your email and password locally visible on your pc

After you have access token you can get your facebook_id from this site:
https://graph.facebook.com/me?access_token=...(Your token)

@ghost
Copy link

ghost commented Dec 4, 2018

@robertmielewczyk Getting this now:

  File "/Volumes/gizmo/Development/Sources/tinder-bot/env/lib/python2.7/site-packages/requests/sessions.py", line 140, in resolve_redirects
    raise TooManyRedirects('Exceeded %s redirects.' % self.max_redirects, response=resp)
requests.exceptions.TooManyRedirects: Exceeded 30 redirects.

Any ideas?

@robertmielewczyk
Copy link

For now I will leave a manual way of getting this token and soon I will upload a python version.
I'm getting the same error and I'm not sure why (Mistake is in the authorization website somehow its making too many redirects and I don't think it did that a month ago)

Getting Access_Token Manual Way: (Thanks to 'fbessez' comment)
New URL for token

STEPS:

  1. Before Hitting 'OK' open developer tools --> (ctrl + shift + i ) <-- On Chrome
  2. Navigate to Network Tab
  3. Hit 'OK', in the Name sidebar 'confirm?dpr=' should appear, click on it and click on Response Tab
  4. you should see something like for (;;);{"...."} search for access_token there

Once you have your token you can start playing with tinder API
Link for Great documentation of possible API calls (Works December 2018)

To quick start anyone to see if the api is working with the token here's an authorization call:

curl -X POST https://api.gotinder.com/auth   -H "Content-Type: application/json"   -d '{
  "facebook_token":"asdklnalnwlknqyeahthosearerandomletters",
  "facebook_id":"ActuallyAnythingButYouCanPutYourIdHere"
}'

@SolbiatiAlessandro
Copy link

For now I will leave a manual way of getting this token and soon I will upload a python version.
I'm getting the same error and I'm not sure why (Mistake is in the authorization website somehow its making too many redirects and I don't think it did that a month ago)

Getting Access_Token Manual Way: (Thanks to 'fbessez' comment)
New URL for token

STEPS:

  1. Before Hitting 'OK' open developer tools --> (ctrl + shift + i ) <-- On Chrome
  2. Navigate to Network Tab
  3. Hit 'OK', in the Name sidebar 'confirm?dpr=' should appear, click on it and click on Response Tab
  4. you should see something like for (;;);{"...."} search for access_token there

Once you have your token you can start playing with tinder API
Link for Great documentation of possible API calls (Works December 2018)

To quick start anyone to see if the api is working with the token here's an authorization call:

curl -X POST https://api.gotinder.com/auth   -H "Content-Type: application/json"   -d '{
  "facebook_token":"asdklnalnwlknqyeahthosearerandomletters",
  "facebook_id":"ActuallyAnythingButYouCanPutYourIdHere"
}'

working perfectly! Thank you very much

@ghost
Copy link

ghost commented Dec 8, 2018

Guys! I think our issue is related to the User Agent string. Not sure why/how, but on my side i just switched it to Safari (most recent) and used the facebook desktop link. Tweaked the original code:

import robobrowser
import re


class UserAgent:
    class Mobile:
        class iOS:
            safari = 'Mozilla/5.0 (iPhone; CPU iPhone OS 11_0 like Mac OS X) AppleWebKit/604.1.38 (KHTML, like Gecko) Version/11.0 Mobile/15A356 Safari/604.1'

class Facebook:

    AUTHAPP_FORM_ACTION = '/v2.8/dialog/oauth/confirm'
    AUTH_URL = "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"

    def __init__(self, username, password, user_agent=None):
        self.username = username
        self.password = password

        self.user_agent = user_agent
        if not self.user_agent:
            self.user_agent = UserAgent.Mobile.iOS.safari

        self.browser = robobrowser.RoboBrowser(user_agent=self.user_agent, parser="lxml")

    def get_access_token(self):        
        self.browser.open(self.AUTH_URL)

        # Authentication
        login_form = self.browser.get_form()
        login_form["pass"] = self.password
        login_form["email"] = self.username
        self.browser.submit_form(login_form)

        # Authorizing App
        authapp_form = self.browser.get_form(action=self.AUTHAPP_FORM_ACTION)
        if authapp_form.submit_fields.get('__CONFIRM__'):
            self.browser.submit_form(authapp_form, submit=authapp_form.submit_fields['__CONFIRM__'])
        else:
            raise Exception("Couldn't find the continue button. Maybe you supplied the wrong login credentials? Or maybe Facebook is asking a security question?")
        self.access_token = re.search(r"access_token=([\w\d]+)", self.browser.response.content.decode()).groups()[0]
        return self.access_token

if __name__ == '__main__':
    username = 'your@email.com'
    password = 'yourpassword'
    facebook = Facebook(username, password)
    print facebook.get_access_token()

Hope it will work for you guys as well! Let's get back on the Tinder game XD

@dhrumin75
Copy link

Guys! I think our issue is related to the User Agent string. Not sure why/how, but on my side i just switched it to Safari (most recent) and used the facebook desktop link. Tweaked the original code:

import robobrowser
import re


class UserAgent:
    class Mobile:
        class iOS:
            safari = 'Mozilla/5.0 (iPhone; CPU iPhone OS 11_0 like Mac OS X) AppleWebKit/604.1.38 (KHTML, like Gecko) Version/11.0 Mobile/15A356 Safari/604.1'

class Facebook:

    AUTHAPP_FORM_ACTION = '/v2.8/dialog/oauth/confirm'
    AUTH_URL = "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"

    def __init__(self, username, password, user_agent=None):
        self.username = username
        self.password = password

        self.user_agent = user_agent
        if not self.user_agent:
            self.user_agent = UserAgent.Mobile.iOS.safari

        self.browser = robobrowser.RoboBrowser(user_agent=self.user_agent, parser="lxml")

    def get_access_token(self):        
        self.browser.open(self.AUTH_URL)

        # Authentication
        login_form = self.browser.get_form()
        login_form["pass"] = self.password
        login_form["email"] = self.username
        self.browser.submit_form(login_form)

        # Authorizing App
        authapp_form = self.browser.get_form(action=self.AUTHAPP_FORM_ACTION)
        if authapp_form.submit_fields.get('__CONFIRM__'):
            self.browser.submit_form(authapp_form, submit=authapp_form.submit_fields['__CONFIRM__'])
        else:
            raise Exception("Couldn't find the continue button. Maybe you supplied the wrong login credentials? Or maybe Facebook is asking a security question?")
        self.access_token = re.search(r"access_token=([\w\d]+)", self.browser.response.content.decode()).groups()[0]
        return self.access_token

if __name__ == '__main__':
    username = 'your@email.com'
    password = 'yourpassword'
    facebook = Facebook(username, password)
    print facebook.get_access_token()

Hope it will work for you guys as well! Let's get back on the Tinder game XD

@vyscond
is it sill working ? i am getting followling error:
Traceback (most recent call last): File "C:/Users/Dhrumin/PycharmProjects/tinderproj/auth.py", line 48, in <module> print(facebook.get_access_token()) File "C:/Users/Dhrumin/PycharmProjects/tinderproj/auth.py", line 37, in get_access_token if authapp_form.submit_fields.get('__CONFIRM__'): AttributeError: 'NoneType' object has no attribute 'submit_fields'

@ghost
Copy link

ghost commented Apr 15, 2020

@dhrumin75 Did you tried opening up the facebook link on your browser to check if the page is loading properly?

@dhrumin75
Copy link

@dhrumin75 Did you tried opening up the facebook link on your browser to check if the page is loading properly?

@vyscond the page opens with a tinder dialog box but the 'Continue' or 'OK' buttons are not showing up. Just a plain Dialog box. Here's the screenshot

@ghost
Copy link

ghost commented Apr 17, 2020

@dhrumin75 Weird. Try render it as mobile browser.

@dhrumin75
Copy link

@dhrumin75 Weird. Try render it as mobile browser.

@vyscond well this worked, Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants