Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

OAuth in Google Data API using Java

Does anyone know any web application example where Oauth has been used in with google data API?

like image 271
yogsma Avatar asked Dec 31 '25 04:12

yogsma


1 Answers

From what I understand (correct me if I'm wrong). In order to get the request token back set the oauth_callback to the absolute path where the oauth_token will be appended to the oath_callback.

From (http://code.google.com/apis/gdata/docs/auth/oauth.html)

Extracting the token from the callback URL

When Google redirects back to your application, the oauth_token is appended to the "oauth_callback_url" URL as a query parameter. Your application should then extract the token value from its URL query parameter and re-establish the oauth parameters.

If you're using Google OAuth helper, then you can try this example.

import com.google.gdata.client.docs.*;
import com.google.gdata.client.authn.oauth.*;

String CONSUMER_KEY = "example.com";
String CONSUMER_SECRET = "abc123doremi";

GoogleOAuthParameters oauthParameters = new GoogleOAuthParameters();
oauthParameters.setOAuthConsumerKey(CONSUMER_KEY);
oauthParameters.setOAuthConsumerSecret(CONSUMER_SECRET);
oauthParameters.setScope("https://docs.google.com/feeds/");
oauthParameters.setOAuthCallback("http://www.example.com/UpgradeToken.jsp");

GoogleOAuthHelper oauthHelper = new GoogleOAuthHelper(new OAuthHmacSha1Signer());
oauthHelper.getUnauthorizedRequestToken(oauthParameters);

This example seemed to have been written inside a JSP. You can use it using Frameworks.

The oauthParameters.setOAuthCallback() is where Google added their callback URL path to ensure their token are returned.

like image 108
Buhake Sindi Avatar answered Jan 02 '26 16:01

Buhake Sindi



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!