0

This my code someone say were i missed it

OAuthRsaSha1Signer rsaSigner = new OAuthRsaSha1Signer();
            com.google.gdata.client.authn.oauth.OAuthParameters params = new com.google.gdata.client.authn.oauth.OAuthParameters();
            params.setOAuthConsumerKey(oauthconsumerkey);
            params.setOAuthNonce(Util.getNonce());
            params.setOAuthTimestamp(Util.getTimestamp());
            params.setOAuthSignatureMethod("RSA-SHA1");
            params.setOAuthType(com.google.gdata.client.authn.oauth.OAuthParameters.OAuthType.TWO_LEGGED_OAUTH);
            params.addCustomBaseParameter("oauth_version", "1.0");
            rsaSigner.setPrivateKey(privKey);
            String method = "GET";
            if (body != null && body.length() > 0) {
                method = "POST";
                MessageDigest digest = MessageDigest.getInstance("SHA-1");
                digest.reset();
                byte[] hash = digest.digest(body.getBytes("UTF-8"));
                String encodedHash = Base64.encode(hash);
                params.addCustomBaseParameter("oauth_body_hash", encodedHash);
            }
            String baseString = OAuthUtil.getSignatureBaseString(httpsURL, method, params.getBaseParameters());
            String signature = rsaSigner.getSignature(baseString, params);
            params.addCustomBaseParameter("oauth_signature", signature);

            URL url = new URL(httpsURL);
            con = (HttpsURLConnection) url.openConnection();
            con.setRequestMethod(method);
            con.setSSLSocketFactory((SSLSocketFactory) SSLSocketFactory.getDefault());
            con.setDoOutput(true);
            con.setDoInput(true);
            con.addRequestProperty("Authorization", buildAuthHeaderString(params));
            System.out.println(buildAuthHeaderString(params));

            if (body != null && body.length() > 0) {
                con.addRequestProperty("content-type", "application/xml; charset=UTF-8");
                con.addRequestProperty("content-length", Integer.toString(body.length()));
            }
            con.connect();

            if (body != null && body.length() > 0) {
                CharsetEncoder encoder = Charset.forName("UTF-8").newEncoder();
                OutputStreamWriter request = new OutputStreamWriter(con.getOutputStream(), encoder);
                request.append(body);
                request.flush();
                request.close();
            }
2
Contributors
1
Reply
15
Views
2 Years
Discussion Span
Last Post by Ewald Horn
0

Well, 400 means your request is bad. Have you traced your POST and taken a look at the actual request that is sent? Using Charles Proxy, you can easily see what request are being sent, and then see where the problem is.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.