Python backend, Login with facebook, error: "An active access token must be used to.." -


i create working "login facebook" button. there many posts on issue cannot find 1 tat helps.

it works. short lived token to, app-id , client secret, request access token. , access token in json. however, when append so: 'https://graph.facebook.com/v2.4/me?%s&fields=name,id,email' % token

i dreaded:

an active access token must used query information current user

here's output (... = elipsis):

    short lived access token received 2q ... 8zd      send request long lived access token to: https://graph.facebook.com/oauth/access_token?grant_type=fb_exchange_token&client_id=1234 ... 3c8&fb_exchange_token=2q ... 8zd  result = h.request(url, 'get')[1] was: {"access_token":"abc ... mn","token_type":"bearer","expires_in":5174030}      token now: abc...mn      url sent api access:https://graph.facebook.com/v2.4/me?abc...mn&fields=name,id,email      api json result: {"error":{"message":"an active access token must used query information current user.","type":"oauthexception","code":2500,"fbtrace_id":"cq8fmavqtnl"}} 

it stems original code:

def fbconnect():     """connect facebook."""     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 "short lived access token received %s " % access_token      app_id = json.loads(open('fb_client_secrets.json', 'r').read())[         'web']['app_id']     app_secret = json.loads(         open('fb_client_secrets.json', 'r').read())['web']['app_secret']     url = 'https://graph.facebook.com/oauth/access_token?grant_type=fb_exchange_token&client_id=%s&client_secret=%s&fb_exchange_token=%s' % (         app_id, app_secret, access_token)     print "send request long lived access token to: "+url     h = httplib2.http()     result = h.request(url, 'get')[1]     print "result = h.request(url, 'get')[1] was: " + result     token = json.loads(result)  # h.request(url, 'get')[0]     # print "token now: " + token     token = token['access_token']     token = str(token)     print "token now: " + token     # use token user info api     # userinfo_url = "https://graph.facebook.com/v2.4/me"       url = 'https://graph.facebook.com/v2.4/me?%s&fields=name,id,email' % token     h = httplib2.http()     result = h.request(url, 'get')[1]     print "url sent 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"] 


Comments

Popular posts from this blog

php - Permission denied. Laravel linux server -

google bigquery - Delta between query execution time and Java query call to finish -

python - Pandas two dataframes multiplication? -