def connect_facebook(): """ (PUT: social_connect/facebook) """ from unifide_backend.action.social.facebook.sdk import get_access_token_from_code from unifide_backend.action.social.facebook.action import get_fb_id, save_fb_user from unifide_backend.action.admin.user.action import get_user verb = "put" noun = "social_connect/facebook" #req_vars user_id = request.form.get("user_id") facebook_code = request.form.get("code") brand_name = request.form.get("brand_name") #auth check #to-do user = get_user(user_id) result = get_access_token_from_code(facebook_code, FB_REDIRECT_URI, FB_APP_ID, FB_APP_SECRET) access_token = result["access_token"] token_expiry = result["expires"] if "expires" in result else None fb_id = get_fb_id(access_token) fb_user = save_fb_user(user.get_id(), brand_name, fb_id, access_token, token_expiry) if fb_user is None: return jsonify({"status": "error", "error": "Fail to save user access token"}) return jsonify({"status": "ok"})
def _test_connect_facebook(self): print "test_connect_facebook" from unifide_backend.action.social.facebook.sdk import get_access_token_from_code from unifide_backend.action.social.facebook.action import get_fb_id, save_fb_user from unifide_backend.action.admin.user.action import get_user user_id = "xaa8LzkwtCCgb6BeP" facebook_code = "AQDGTtp1SjVpa1TeKcTfvikm909c56L9ObIWDmLayRYPSJ_qGFN8SPfEZRRTe6V0-XwKh45Vcd6BZAkFxXWsUGlBKNGkyZ1ToKGZztByuZgDYMnoUg-4nv2_nMrE60QmoHBYs4OpW6RjTWAUBUgdwv2vGuxzR1EPHIbpvT2zklVPXfnQbIotY6ulMLAhO-6iyzhVS7UWWA9QJzms6JymFv7T#_=_" user = get_user(user_id) result = get_access_token_from_code(facebook_code, FB_REDIRECT_URI, FB_APP_ID, FB_APP_SECRET) access_token, token_expiry = result["access_token"], result["expires"] fb_id = get_fb_id(access_token) fb_user = save_fb_user(user.get_id(), fb_id, access_token, token_expiry) assert fb_user.get_id() print fb_user.get_id()