Skip to content

Instantly share code, notes, and snippets.

@gitssk
Created August 21, 2013 12:18
Show Gist options
  • Save gitssk/6293751 to your computer and use it in GitHub Desktop.
Save gitssk/6293751 to your computer and use it in GitHub Desktop.
Passing data using HTTP GET/OAuth
import com.google.gdata.client.GoogleService;
import com.google.gdata.client.authn.oauth.*;
import com.google.gdata.data.BaseEntry;
import com.google.gdata.data.BaseFeed;
import com.google.gdata.data.Feed;
import java.io.*;
import java.net.*;
import javax.net.ssl.*;
public class PPB {
public static void main(String argv[]) throws Exception {
HttpURLConnection con = null;
OAuthHmacSha1Signer hmacSigner = new OAuthHmacSha1Signer();
OAuthParameters params = new OAuthParameters();
params.setOAuthConsumerKey("");
params.setOAuthConsumerSecret("");
params.setOAuthNonce(OAuthUtil.getNonce());
params.setOAuthTimestamp(OAuthUtil.getTimestamp());
params.setOAuthSignatureMethod("HMAC-SHA1");
params.addCustomBaseParameter("oauth_version", "1.0");
String payload = "</payloadData>";
params.addCustomBaseParameter("payload", payload);
String method = "GET";
String ppURL = "http://reqURL";
String baseString = OAuthUtil.getSignatureBaseString(ppURL, method, params.getBaseParameters());
String signature = hmacSigner.getSignature(baseString, params);
params.addCustomBaseParameter("oauth_signature", signature);
//TODO: Use StringBuilder
ppURL += "?";
ppURL += "oauth_consumer_key=";
String cb = URLEncoder.encode(params.getBaseParameters().get("oauth_consumer_key"));
ppURL += cb;
ppURL += "&";
ppURL += "oauth_nonce=";
cb = URLEncoder.encode(params.getBaseParameters().get("oauth_nonce"));
ppURL += cb;
ppURL += "&";
ppURL += "oauth_signature=";
cb = URLEncoder.encode(params.getBaseParameters().get("oauth_signature"));
ppURL += cb;
ppURL += "&";
ppURL += "oauth_signature_method=";
cb = URLEncoder.encode(params.getBaseParameters().get("oauth_signature_method"));
ppURL += cb;
ppURL += "&";
ppURL += "oauth_timestamp=";
cb = URLEncoder.encode(params.getBaseParameters().get("oauth_timestamp"));
ppURL += cb;
ppURL += "&";
ppURL += "oauth_version=";
cb = URLEncoder.encode(params.getBaseParameters().get("oauth_version"));
ppURL += cb;
ppURL += "&";
ppURL += "payload=";
cb = URLEncoder.encode(params.getBaseParameters().get("payload"));
ppURL += cb;
System.out.println(ppURL);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment