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

[FIX] here's my fix to fbconnect() in Graph API v3.2 #72

Open
oliveira-marcio opened this issue Oct 28, 2018 · 0 comments
Open

[FIX] here's my fix to fbconnect() in Graph API v3.2 #72

oliveira-marcio opened this issue Oct 28, 2018 · 0 comments

Comments

@oliveira-marcio
Copy link

fbconnect() in project.py isn't working as it is using v3.2 Graph API. Here's my solution that even doesn't requires local fb_client_secrets.json anymore:

@app.route('/fbconnect', methods=['POST'])
def fbconnect():
    if request.args.get('state') != login_session['state']:
        response = make_response(json.dumps('Invalid state parameter.'), 401)
        response.headers['Content-Type'] = 'application/json'
        return response
    access_token = request.data
    print "access token received %s " % access_token

    # Use token to get user info from API
    userinfo_url = "https://graph.facebook.com/me"

    url = '%s?access_token=%s&fields=name,id,email,picture' % (userinfo_url, access_token)
    h = httplib2.Http()
    result = h.request(url, 'GET')[1]
    # print "url sent for API access:%s"% url
    # print "API JSON result: %s" % result
    data = json.loads(result)
    login_session['provider'] = 'facebook'
    login_session['username'] = data["name"]
    login_session['email'] = data["email"]
    login_session['facebook_id'] = data["id"]

    # The token must be stored in the login_session in order to properly logout
    login_session['access_token'] = access_token

    # Get user picture
    login_session['picture'] = data["picture"]["data"]["url"]

    # see if user exists
    user_id = getUserID(login_session['email'])
    if not user_id:
        user_id = createUser(login_session)
    login_session['user_id'] = user_id

    output = ''
    output += '<h1>Welcome, '
    output += login_session['username']

    output += '!</h1>'
    output += '<img src="'
    output += login_session['picture']
    output += ' " style = "width: 300px; height: 300px;border-radius: 150px;-webkit-border-radius: 150px;-moz-border-radius: 150px;"> '

    flash("Now logged in as %s" % login_session['username'])
    return output
@oliveira-marcio oliveira-marcio changed the title [FIX] here's my fix to fbconnect() [FIX] here's my fix to fbconnect() in Graph API v3.2 Oct 28, 2018
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

1 participant