开发者

OAuth in Google Data API using Java

Does anyone know any web application e开发者_StackOverflow中文版xample where Oauth has been used in with google data API?


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜