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);
// Get the authorization url. The user of your application must visit
// this url in order to authorize with Google. If you are building a
// browser-based application, you can redirect the user to the authorization
// url.
String requestUrl = oauthHelper.createUserAuthorizationUrl(oauthParameters);
System.out.println(requestUrl);
System.out.println("Please visit the URL above to authorize your OAuth "
+ "request token. Once that is complete, press any key to "
+ "continue...");
System.in.read();
////////////////////////////////////////////////////////////////////////////
// STEP 4: Get the Access Token
////////////////////////////////////////////////////////////////////////////
// Once the user authorizes with Google, the request token can be exchanged
// for a long-lived access token. If you are building a browser-based
// application, you should parse the incoming request token from the url and
// set it in GoogleOAuthParameters before calling getAccessToken().
String token = oauthHelper.getAccessToken(oauthParameters);
System.out.println("OAuth Access Token: " + token);
System.out.println();
////////////////////////////////////////////////////////////////////////////
// STEP 5: Make an OAuth authorized request to Google
////////////////////////////////////////////////////////////////////////////
// Initialize the variables needed to make the request
URL feedUrl = new URL(variables.getFeedUrl());
System.out.println("Sending request to " + feedUrl.toString());
System.out.println();
GoogleService googleService =
new GoogleService(variables.getGoogleServiceName(), "oauth-sample-app");
// Set the OAuth credentials which were obtained from the step above.
googleService.setOAuthCredentials(oauthParameters, signer);
// Make the request to Google
BaseFeed resultFeed = googleService.getFeed(feedUrl, Feed.class);
System.out.println("Response Data:");
System.out.println("=====================================================");
System.out.println("| TITLE: " + resultFeed.getTitle().getPlainText());
if (resultFeed.getEntries().size() == 0) {
System.out.println("|\tNo entries found.");
} else {
for (int i = 0; i < resultFeed.getEntries().size(); i++) {
BaseEntry entry = (BaseEntry) resultFeed.getEntries().get(i);
System.out.println("|\t" + (i + 1) + ": "
+ entry.getTitle().getPlainText());
}
}
System.out.println("=====================================================");
System.out.println();
////////////////////////////////////////////////////////////////////////////
// STEP 6: Revoke the OAuth token
////////////////////////////////////////////////////////////////////////////
System.out.println("Revoking OAuth Token...");
oauthHelper.revokeToken(oauthParameters);
System.out.println("OAuth Token revoked...");
}