0

I'm developing GWTP project, and below scenarios are tested successfully in my local development mode :

  1. Get authenticated and authorized by OpenID and OAuth
  2. Save GoogleOAuthParameters object into HttpSession.
  3. Another action handler reuses the GoogleOAuthParameters stored in session to get SpreadsheetService object.
  4. Use SpreadsheetService to manipulate spread sheets in GDoc.

However, when being deployed to App Engine, nothing can be read from GDoc, and no error/warning also, and returned list is always empty.

spreadsheetService = new SpreadsheetService("test");
GoogleOAuthParameters oauthParameters = (GoogleOAuthParameters)sessionProvider.get().getAttribute(HttpSessionProvider.PARAM_OAUTH_PARAMETERS);
spreadsheetService.setOAuthCredentials(oauthParameters, new OAuthHmacSha1Signer());
oauthParameters.setScope(SCOPE_SPREADSHEET);

If I clearly use username/password as below when initializing SpreadsheetService, I can retrieve data from GDoc.

SpreadsheetService sService = new SpreadsheetService("test");
sService.setUserCredentials("username", "password");

I'm using App Engine SDK 1.6.6, and gdata-spreadsheet-3.0. Please advise whether anything I did wrongly. Thanks!

Softhinker.com
  • 895
  • 2
  • 11
  • 25
  • Just a suggestion: both OAuth 1.0 and ClientLogin are deprecated authentication methods. I would advise you using OAuth 2.0 instead. – alex Jun 03 '12 at 17:44

2 Answers2

0

The documentation is for .Net, not Java. If you want to develop in Java, I found a solution here: Sharing authentication/token between Android Google Client API and SpreadSheet API 3.0

  String token = GoogleAuthUtil.getToken(
          this,
          this.accountName,
          this.scopes);

  SpreadsheetService service = new SpreadsheetService("my-service-name");

  service.setProtocolVersion(SpreadsheetService.Versions.V3);
  service.setHeader("Authorization", "Bearer " + token);

Note that this does not work for setting the token and results in a 401 for me:

  // BAD CODE
  service.setUserToken(token);
  // BAD CODE
Community
  • 1
  • 1
MattD
  • 1,324
  • 4
  • 14
  • 28
-2

The documentation has complete samples in Java showing how to perform authentication with all supported mechanisms. The recommendation is to use OAuth 2.0 which is explained at:

https://developers.google.com/google-apps/spreadsheets/#performing_oauth_20

Claudio Cherubino
  • 14,896
  • 1
  • 35
  • 42
  • The documentation for OAuth is only in .Net. How do you do this in Java? The classes they use in .Net do not seem to be available in Java. – MattD Feb 09 '15 at 05:20