private AccessToken requestAccessToken(Map<String, String> params)
            throws AuthorizationException {
        try {
            HttpRequest request = HttpRequest.post("https://graph.renren.com/oauth/token");
            request.form(params);
            int statusCode = request.code();
            String body = request.body();
            JSONObject response = new JSONObject(body);

            if (statusCode == HttpURLConnection.HTTP_OK && response.has("access_token")) {
                String accessToken = response.getString("access_token");
                String refreshToken = response.has("refresh_token") ? response
                        .getString("refresh_token") : null;
                String macKey = response.has("mac_key") ? response.getString("mac_key") : null;
                String macAlgorithm = response.has("mac_algorithm") ? response
                        .getString("mac_algorithm") : null;

                AccessToken.Type type = response.has("mac_algorithm")
                        && response.has("mac_algorithm") ? AccessToken.Type.MAC
                        : AccessToken.Type.Bearer;

                return new AccessToken(type, accessToken, refreshToken, macKey, macAlgorithm);

            } else {
                throw new AuthorizationException("Authorization failed with Authorization Code. "
                        + response.getString("error") + ": "
                        + response.getString("error_description"));
            }

        } catch (HttpRequestException e) {
            throw new AuthorizationException("Authorization failed. Failed to send http request");
        } catch (JSONException e) {
            throw new AuthorizationException("Parse OAuth response failed. " + e.getMessage());
        }
    }