English 中文(简体)
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();

// DocsService 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);




相关问题
How to make logging.debug work on Appengine?

I m having a tough time getting the logging on Appengine working. the statement import logging is flagged as an unrecognized import in my PyDev Appengine project. I suspected that this was just an ...

gqlQuery returns object, want list of keys

Is there a way to convert the GqlQuery object to an array of keys, or is there a way to force the query to return an array of keys? For example: items = db.GqlQuery("SELECT __key__ FROM Items") ...

Integrating Google AppEngine with a Thick Client

I want to make a multi-user client-server solution with Java Swing thick client as a front-end and Google AppEngine (Java one) as a back-end. The problem is that GAE provides only web-based forms for ...

sorl.thumbnail : thumbnail is not a valid tag library?

I am trying to install sorl.thumbnail but am getting the following error message: thumbnail is not a valid tag library: Could not load template library from django.templatetags.thumbnail, No module ...

热门标签