Package facebook4j.internal.http

Examples of facebook4j.internal.http.HttpResponse


    private HttpResponse get(String url, HttpParameter[] parameters) throws FacebookException {
        if (!conf.isMBeanEnabled()) {
            return http.get(url, parameters, (containsAccessToken(parameters) ? null : auth));
        } else {
            // intercept HTTP call for monitoring purposes
            HttpResponse response = null;
            long start = System.currentTimeMillis();
            try {
                response = http.get(url, parameters, (containsAccessToken(parameters) ? null : auth));
            } finally {
                long elapsedTime = System.currentTimeMillis() - start;
View Full Code Here


    private HttpResponse getRaw(String url) throws FacebookException {
        if (!conf.isMBeanEnabled()) {
            return http.get(url);
        } else {
            // intercept HTTP call for monitoring purposes
            HttpResponse response = null;
            long start = System.currentTimeMillis();
            try {
                response = http.get(url);
            } finally {
                long elapsedTime = System.currentTimeMillis() - start;
View Full Code Here

    private HttpResponse post(String url) throws FacebookException {
        if (!conf.isMBeanEnabled()) {
            return http.post(url, auth);
        } else {
            // intercept HTTP call for monitoring purposes
            HttpResponse response = null;
            long start = System.currentTimeMillis();
            try {
                response = http.post(url, auth);
            } finally {
                long elapsedTime = System.currentTimeMillis() - start;
View Full Code Here

    private HttpResponse post(String url, HttpParameter[] parameters) throws FacebookException {
        if (!conf.isMBeanEnabled()) {
            return http.post(url, parameters, (containsAccessToken(parameters) ? null : auth));
        } else {
            // intercept HTTP call for monitoring purposes
            HttpResponse response = null;
            long start = System.currentTimeMillis();
            try {
                response = http.post(url, parameters, (containsAccessToken(parameters) ? null : auth));
            } finally {
                long elapsedTime = System.currentTimeMillis() - start;
View Full Code Here

    private HttpResponse delete(String url) throws FacebookException {
        if (!conf.isMBeanEnabled()) {
            return http.delete(url, auth);
        } else {
            // intercept HTTP call for monitoring purposes
            HttpResponse response = null;
            long start = System.currentTimeMillis();
            try {
                response = http.delete(url, auth);
            } finally {
                long elapsedTime = System.currentTimeMillis() - start;
View Full Code Here

    private HttpResponse delete(String url, HttpParameter[] parameters) throws FacebookException {
        if (!conf.isMBeanEnabled()) {
            return http.delete(url, parameters, (containsAccessToken(parameters) ? null : auth));
        } else {
            // intercept HTTP call for monitoring purposes
            HttpResponse response = null;
            long start = System.currentTimeMillis();
            try {
                response = http.delete(url, parameters, (containsAccessToken(parameters) ? null : auth));
            } finally {
                long elapsedTime = System.currentTimeMillis() - start;
View Full Code Here

        return url;
    }

    public AccessToken getOAuthAccessToken(String oauthCode) throws FacebookException {
        String url = getExchangeAccessTokenURL(oauthCode);
        HttpResponse response = http.get(url);
        if (response.getStatusCode() != 200) {
            throw new FacebookException("authorization failed.");
        }
        this.oauthToken = new AccessToken(response);
        return this.oauthToken;
    }
View Full Code Here

        return this.oauthToken;
    }
   
    public AccessToken getOAuthAppAccessToken() throws FacebookException {
        String url = getAppAccessTokenURL();
        HttpResponse response = http.get(url);
        if (response.getStatusCode() != 200) {
            throw new FacebookException("authorization failed.");
        }
        this.oauthToken = new AccessToken(response);
        return this.oauthToken;
    }
View Full Code Here

    public void signinWithFacebook() throws Exception {
        CookieHandler.setDefault(new ListCookieHandler());

        Facebook facebook = new FacebookFactory().getInstance();
        HttpClientImpl http = new HttpClientImpl();
        HttpResponse response;
       
        String oAuthAppId = p.getProperty("oauth.appId");
        String oAuthAppSecret = p.getProperty("oauth.appSecret");
        facebook.setOAuthAppId(oAuthAppId, oAuthAppSecret);
        facebook.setOAuthPermissions("email");

        // auth
        String callbackURL = p.getProperty("login.callbackURL");
        String authorizationURL = facebook.getOAuthAuthorizationURL(callbackURL);
        response = http.get(authorizationURL);

        // login
        String loginURL = response.getResponseHeader("Location");
        response = http.get(loginURL);

        String resStr = response.asString();
        String authorizeURL = "https://www.facebook.com" + catchPattern(resStr, "<form id=\"login_form\" action=\"", "\" method=\"post\"");
        HttpParameter[] params = new HttpParameter[18];
        params[0] = new HttpParameter("lsd", catchPattern(resStr
                    , "<input type=\"hidden\" name=\"lsd\" value=\"", "\" autocomplete=\"off\" />"));
        params[1] = new HttpParameter("api_key", catchPattern(resStr
                    , "<input type=\"hidden\" autocomplete=\"off\" id=\"api_key\" name=\"api_key\" value=\"", "\" />"));
        params[2] = new HttpParameter("display", "page");
        params[3] = new HttpParameter("enable_profile_selector", "");
        params[4] = new HttpParameter("legacy_return", "1");
        params[5] = new HttpParameter("next", catchPattern(resStr
                    , "<input type=\"hidden\" autocomplete=\"off\" id=\"next\" name=\"next\" value=\"", "\" />"));
        params[6] = new HttpParameter("profile_selector_ids", "");
        params[7] = new HttpParameter("skip_api_login", "1");
        params[8] = new HttpParameter("signed_next", "1");
        params[9] = new HttpParameter("trynum", "1");
        params[10] = new HttpParameter("timezone", "");
        params[11] = new HttpParameter("lgnrnd", catchPattern(resStr
                    , "<input type=\"hidden\" name=\"lgnrnd\" value=\"", "\" />"));
        params[12] = new HttpParameter("lgnjs", catchPattern(resStr
                    , "<input type=\"hidden\" id=\"lgnjs\" name=\"lgnjs\" value=\"", "\" />"));
        params[13] = new HttpParameter("email", p.getProperty("login.email"));
        params[14] = new HttpParameter("pass", p.getProperty("login.password"));
        params[15] = new HttpParameter("persistent", "1");
        params[16] = new HttpParameter("default_persistent", "0");
        params[17] = new HttpParameter("login", "&#x30ed;&#x30b0;&#x30a4;&#x30f3;");

        response = http.request(new HttpRequest(RequestMethod.POST, authorizeURL, params, null, null));

        // dialog
        String dialogURL = response.getResponseHeader("Location").replaceAll("&amp%3B", "&");
        response = http.request(new HttpRequest(RequestMethod.GET, dialogURL, null, null, null));
        if (null != response.getResponseHeader("Location")) {
            String redirectURL = response.getResponseHeader("Location");
            assertThat(redirectURL.contains("code"), is(true));
            return;
        }

        // read
        resStr = response.asString();
        String readURL = "https://www.facebook.com" + catchPattern(resStr, "id=\\\"platformDialogForm\\\" action=\\\"", "\" method=\\\"post\\\"").replaceAll("\\\\", "");
        params = new HttpParameter[18];
        params[0] = new HttpParameter("fb_dtsg", catchPattern(resStr
                    , "name=\\\"fb_dtsg\\\" value=\\\"", "\\\" autocomplete=\\\"off\\\" \\/>"));
        params[1] = new HttpParameter("app_id", oAuthAppId);
        params[2] = new HttpParameter("redirect_uri", callbackURL);
        params[3] = new HttpParameter("display", "page");
        params[4] = new HttpParameter("access_token", "");
        params[5] = new HttpParameter("sdk", "");
        params[6] = new HttpParameter("from_post", "1");
        params[7] = new HttpParameter("public_info_nux", catchPattern(resStr
                    , "name=\\\"public_info_nux\\\" value=\\\"", "\\\" \\/>"));
        params[8] = new HttpParameter("login", catchPattern(resStr
                    , "name=\\\"login\\\" value=\\\"", "\\\" \\/>"));
        params[9] = new HttpParameter("read", catchPattern(resStr
                    , "name=\\\"read\\\" value=\\\"", "\\\" \\/>"));
        params[10] = new HttpParameter("write", catchPattern(resStr
                    , "name=\\\"write\\\" value=\\\"", "\\\" \\/>"));
        params[11] = new HttpParameter("extended", catchPattern(resStr
                    , "name=\\\"extended\\\" value=\\\"", "\\\" \\/>"));
        params[12] = new HttpParameter("confirm", catchPattern(resStr
                    , "name=\\\"confirm\\\" value=\\\"", "\\\" \\/>"));
        params[13] = new HttpParameter("auth_type", "");
        params[14] = new HttpParameter("auth_nonce", "");
        params[15] = new HttpParameter("return_format", catchPattern(resStr
                , "name=\\\"return_format\\\" value=\\\"", "\\\" \\/>"));
        params[16] = new HttpParameter("domain", "");
        params[17] = new HttpParameter("sso_device", "");

        response = http.request(new HttpRequest(RequestMethod.POST, readURL, params, null, null));

        String redirectURL = response.getResponseHeader("Location");
        assertThat(redirectURL.contains("code"), is(true));
    }
View Full Code Here

        ConfigurationBuilder build = new ConfigurationBuilder();
        build.setOAuthAppId(appId);
        build.setOAuthAppSecret(appSecret);
        Configuration configuration = build.build();
        HttpClientWrapper http = new HttpClientWrapper(configuration);
        HttpResponse res = http.get(configuration.getOAuthAccessTokenURL() +
                "?client_id=" + appId +
                "&client_secret=" + appSecret +
                "&grant_type=client_credentials");
        AccessToken at = new AccessToken(res);
        assertThat(at.getToken(), is(notNullValue()));
View Full Code Here

TOP

Related Classes of facebook4j.internal.http.HttpResponse

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.