////////////////////////////////////////////////////////////////////////////
// You first need to initialize a few OAuth-related objects.
// GoogleOAuthParameters holds all the parameters related to OAuth.
// OAuthSigner is responsible for signing the OAuth base string.
GoogleOAuthParameters oauthParameters = new GoogleOAuthParameters();
// Set your OAuth Consumer Key (which you can register at
// https://www.google.com/accounts/ManageDomains).
oauthParameters.setOAuthConsumerKey(variables.getConsumerKey());
// Initialize the OAuth Signer. If you are using RSA-SHA1, you must provide
// your private key as a Base-64 string conforming to the PKCS #8 standard.
// Visit http://code.google.com/apis/gdata/authsub.html#Registered to learn
// more about creating a key/certificate pair. If you are using HMAC-SHA1,
// you must set your OAuth Consumer Secret, which can be obtained at
// https://www.google.com/accounts/ManageDomains.
OAuthSigner signer;
switch (variables.getSignatureMethod()) {
case RSA:
signer = new OAuthRsaSha1Signer(variables.getSignatureKey());
break;
case HMAC:
oauthParameters.setOAuthConsumerSecret(variables.getSignatureKey());
signer = new OAuthHmacSha1Signer();
break;
default:
throw new IllegalArgumentException("Invalid Signature Method");
}
// Finally create a new GoogleOAuthHelperObject. This is the object you
// will use for all OAuth-related interaction.
GoogleOAuthHelper oauthHelper = new GoogleOAuthHelper(signer);
////////////////////////////////////////////////////////////////////////////
// STEP 3: Get the Authorization URL
////////////////////////////////////////////////////////////////////////////
// Set the scope for this particular service.
oauthParameters.setScope(variables.getScope());
// This method also makes a request to get the unauthorized request token,
// and adds it to the oauthParameters object, along with the token secret
// (if it is present).
oauthHelper.getUnauthorizedRequestToken(oauthParameters);