开发者

oauth problem( app engine)

i am trying to pull user's documents data from google docs using oauth, but i cannot understand how to do it

- what's the purpose of oauth_verifier

- how to get the access token secret?

- if i try to use DocsService below, then i have a "server error"

- is there a clear tutorial for this? i cannot find any atm..

    String oauth_verifier = req.getParameter("oauth_verifier");
    String oauth_token = req.getParameter("oauth_token");
    String oauthtokensecret = req.getParameter("oauth_token_secret");

    GoogleOAuthParameters oauthparam = new GoogleOAuthParameters();
    oauthparam.setOAuthConsumerKey("consumer key");
    oauthparam.setOAuthConsumerSecret("secret");
    oauthparam.setOAuthToken(oauth_token);
    oauthparam.setOAuthTokenSecret(oauthtokensecret);
    oauthparam.setOAuthVerifier(oauth_verifier);

    OAuthHmacSha1Signer signer = new OAuthHmacSha1Signer();
    GoogleOAuthHelper oauthhelper = new GoogleOAuthHelper(signer);
    String accesstoken = "";
    String accesstokensecret = "";

    try {
        oauthhelper.getUnauthorizedRequestToken(oauthparam);
        accesstoken = oauthhelper.getAccessToken(oauthparam);
        accesstokensecret = oauthparam.getOAuthTokenSecret();

// Docs开发者_StackOverflowService client = new DocsService("yourCompany-YourAppName-v1"); ...


These may not be what you are looking for, since they are OAuth-specific and not google-related, but I found these "Getting started" articles very helpful:

http://oauth.net/documentation/getting-started


Turns out that I need to get the oauth_token_secret and reuse it later. So (before redirecting user to google login page)

oauthhelper.getUnauthorizedRequestToken(oauthparam);
requesturl = oauthhelper.createUserAuthorizationUrl(oauthparam);
OAuthTokenSecret.tokenSecret = oauthparam.getOAuthTokenSecret();
resp.sendRedirect(requesturl);

Then after the user grants access and we have been redirected to oauth_callback url:

oauthparam.setOAuthToken(oauthtoken);
oauthparam.setOAuthVerifier(oauthverifier);
oauthparam.setOAuthTokenSecret(OAuthTokenSecret.tokenSecret);
oauthhelper.getAccessToken(oauthparam); // access token and access token secret are saved in oauthparam.
// access google service..
GoogleService googleService = new GoogleService( "cp", "test222");
googleService.setOAuthCredentials(oauthparam, signer);
BaseFeed resultFeed = googleService.getFeed(feedUrl, Feed.class);
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜