开发者

Retrieve a document from a google Account with OAuth

I need to know ho开发者_如何学JAVAw to obtain documents from a specific user, the user is authenticated using ...

    UserService userService = UserServiceFactory.getUserService();
    User user = userService.getCurrentUser();

When the user is authenticated , I need to get the documents from google docs. I know I have to use OAuth, but I could not use it correctly.

I hope some one can help me, Thanks.


if i have already a user logged in how can i get his docs

Here is a good reference with way more information than I could provide myself:

http://code.google.com/apis/documents/docs/3.0/developers_guide_java.html

That should get you on the right path.


The user has authenticated to App Engine, but they have not authenticated against any other services, or provided you with access to them. You cannot use their App Engine credentials to access any other services; you will need to follow the standard OAuth authorization procedure in order to access any other services owned by that user.


  1. first do the oauth part using for example signpost library : here is an example ( look at there sample code for Google)
  2. after you complete oauth process in step 1; and store the ACCESS_TOKEN and TOKEN_SECRET you can access google docs service like code snippet below .

(note : CONSUMER_KEY & CONSUMER_SECRET are the ones you get from google and used in step 1 . ACCESS_TOKEN & TOKEN_SECRET are the secret access tokens sent to you by google auth server after you complete oauth process in step 1)

hope this helps.

GoogleOAuthParameters oauthParameters = new GoogleOAuthParameters();
  oauthParameters.setOAuthConsumerKey(CONSUMER_KEY);
  oauthParameters.setOAuthConsumerSecret(CONSUMER_SECRET);
  oauthParameters.setOAuthToken(ACCESS_TOKEN);
  oauthParameters.setOAuthTokenSecret(TOKEN_SECRET);

  DocsService client = new DocsService("yourCompany-YourAppName-v1");
  client.setOAuthCredentials(oauthParameters, new OAuthHmacSha1Signer());

  URL feedUrl = new URL("https://docs.google.com/feeds/default/private/full");
  DocumentListFeed resultFeed = client.getFeed(feedUrl, DocumentListFeed.class);
  for (DocumentListEntry entry : resultFeed.getEntries()) {
    System.out.println(entry.getTitle().getPlainText());
  }
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜