def retrieve_facebook_access_token(oauth_map):
    # Start Facebook access token process
    params = {
        "client_id": App.facebook_app_id,
        "client_secret": App.facebook_app_secret,
        "redirect_uri": get_facebook_token_callback_url(oauth_map),
        "code": oauth_map.facebook_authorization_code,
    }

    response = get_response(FB_URL_ACCESS_TOKEN, params)

    response_params = get_parsed_params(response)
    if not response_params or not response_params.get("access_token"):
        raise OAuthError("Cannot get access_token from Facebook's " +
                         "/oauth/access_token response")

    # Associate our access token and Google/Facebook's
    oauth_map.facebook_access_token = response_params["access_token"][0]

    expires_seconds = 0
    try:
        expires_seconds = int(response_params["expires"][0])
    except (ValueError, KeyError):
        pass

    if expires_seconds:
        oauth_map.expires = (datetime.datetime.now() +
                             datetime.timedelta(seconds=expires_seconds))

    return oauth_map
def get_facebook_app_access_token():
    """Gets the Facebook App Access token

    There is one app access token for the entire Khan Academy Facebook app.
    It is the same for all users and requests. It only changes when the app
    secret changes (very rarely; done through the Facebook developer website),
    so we cache it using setting_model.Setting, which stores
    per-application key-value pairs for app-wide settings. In case the
    Facebook app secret is changed (on the Facebook developer site), the
    request to Facebook is performed for each deployed GAE version.

    More about the app access token here:
    https://developers.facebook.com/docs/opengraph/using-app-tokens/
    """

    params = {
        "client_id": App.facebook_app_id,
        "client_secret": App.facebook_app_secret,
        "grant_type": "client_credentials"
    }

    response = get_response(FB_URL_ACCESS_TOKEN, params)
    response_params = get_parsed_params(response)

    if response_params:
        response_array = response_params.get("access_token")
        if response_array:
            token = response_array[0]
            return token

    raise OAuthError("Cannot get access_token from Facebook's " +
                     "/oauth/access_token response")
def retrieve_facebook_access_token(oauth_map):
    # Start Facebook access token process
    params = {
        "client_id": App.facebook_app_id,
        "client_secret": App.facebook_app_secret,
        "redirect_uri": get_facebook_token_callback_url(oauth_map),
        "code": oauth_map.facebook_authorization_code,
    }

    response = get_response(FB_URL_ACCESS_TOKEN, params)

    response_params = get_parsed_params(response)
    if not response_params or not response_params.get("access_token"):
        raise OAuthError("Cannot get access_token from Facebook's " + "/oauth/access_token response")

    # Associate our access token and Google/Facebook's
    oauth_map.facebook_access_token = response_params["access_token"][0]

    expires_seconds = 0
    try:
        expires_seconds = int(response_params["expires"][0])
    except (ValueError, KeyError):
        pass

    if expires_seconds:
        oauth_map.expires = datetime.datetime.now() + datetime.timedelta(seconds=expires_seconds)

    return oauth_map
def get_facebook_app_access_token():
    """Gets the Facebook App Access token

    There is one app access token for the entire Khan Academy Facebook app.
    It is the same for all users and requests. It only changes when the app
    secret changes (very rarely; done through the Facebook developer website),
    so we cache it using setting_model.Setting, which stores
    per-application key-value pairs for app-wide settings. In case the
    Facebook app secret is changed (on the Facebook developer site), the
    request to Facebook is performed for each deployed GAE version.

    More about the app access token here:
    https://developers.facebook.com/docs/opengraph/using-app-tokens/
    """

    params = {
        "client_id": App.facebook_app_id,
        "client_secret": App.facebook_app_secret,
        "grant_type": "client_credentials",
    }

    response = get_response(FB_URL_ACCESS_TOKEN, params)
    response_params = get_parsed_params(response)

    if response_params:
        response_array = response_params.get("access_token")
        if response_array:
            token = response_array[0]
            return token

    raise OAuthError("Cannot get access_token from Facebook's " + "/oauth/access_token response")
def retrieve_facebook_access_token(oauth_map):
    # Start Facebook access token process
    params = {
                "client_id": App.facebook_app_id,
                "client_secret": App.facebook_app_secret,
                "redirect_uri": get_facebook_token_callback_url(oauth_map),
                "code": oauth_map.facebook_authorization_code,
                }

    try:
        response = get_response(FB_URL_ACCESS_TOKEN, params)
    except Exception, e:
        raise OAuthError(e.message)

    response_params = get_parsed_params(response)
    if not response_params or not response_params.get("access_token"):
        raise OAuthError("Cannot get access_token from Facebook's /oauth/access_token response")
     
    # Associate our access token and Google/Facebook's
    oauth_map.facebook_access_token = response_params["access_token"][0]

    expires_seconds = 0
    try:
        expires_seconds = int(response_params["expires"][0])
    except (ValueError, KeyError):
        pass

    if expires_seconds:
        oauth_map.expires = datetime.datetime.now() + datetime.timedelta(seconds=expires_seconds)
Beispiel #6
0
def retrieve_facebook_access_token(oauth_map):
    # Start Facebook access token process
    params = {
        "client_id": App.facebook_app_id,
        "client_secret": App.facebook_app_secret,
        "redirect_uri": get_facebook_token_callback_url(oauth_map),
        "code": oauth_map.facebook_authorization_code,
    }

    try:
        response = get_response(FB_URL_ACCESS_TOKEN, params)
    except Exception, e:
        raise OAuthError(e.message)

    response_params = get_parsed_params(response)
    if not response_params or not response_params.get("access_token"):
        raise OAuthError(
            "Cannot get access_token from Facebook's /oauth/access_token response"
        )

    # Associate our access token and Google/Facebook's
    oauth_map.facebook_access_token = response_params["access_token"][0]

    expires_seconds = 0
    try:
        expires_seconds = int(response_params["expires"][0])
    except (ValueError, KeyError):
        pass

    if expires_seconds: