1

I have some legacy Java code which uses the V2 Google spreadsheet API to read values from one Google spreadsheet, retrieve some DB values and do some calcs, and update a second Google spreadsheet. With the imminent cutover to OAuth2 authentication only, I need to migrate to the V3 API.

This process gets run from the command line, so the assumption would be that using a service account and a P12 key would be the way forward -- and indeed, we are doing that for using the Google Calendar service.

But it doesn't seem like there is support in place for the spreadsheet service for service accounts. I've seen older references (~2 years ago) to Google Data APIs supporting OAuth2 service accounts through the setOAuth2Credentials() method, but that does not seem to be true today.

Has anyone had any luck in getting the V3 spreadsheet API working with an OAuth2 service account in Java, or can point me to recent (~within the last year) code samples?

halfer
  • 19,824
  • 17
  • 99
  • 186
  • Can you add more information? like the error you get, the code you are using. – Gerardo Apr 01 '15 at 20:34
  • The current code uses ClientLogin, which is not relevant to the discussion. – Daen de Leon Apr 01 '15 at 21:05
  • I meant the new code you are using to try calling the Spreasheet API V3 and the errors you get when doing so. – Gerardo Apr 01 '15 at 22:33
  • That's what my question is -- I don't know how to get OAuth2 service accounts to work with the V3 API. At all. I don't have any errors to report, because there's no code -- I cannot find a hook in the V3 API that might even be useful for OAuth2 service accounts. – Daen de Leon Apr 02 '15 at 00:42
  • Check this answer: http://stackoverflow.com/questions/13229294/how-do-i-create-a-google-spreadsheet-with-a-service-account-and-share-to-other-g – Gerardo Apr 02 '15 at 17:59
  • Thanks Gerardo! But the problem with that link from 2012 is that it references the setOAuth2Credentials() that I mentioned in my OP, which isn't supported in the GData APIs any more, for reasons I don't understand. That's why I'm looking for more recent examples. My boss & I have just discussed migrating away from Google Spreadsheets in favour of a mySQL-managed data solution, and I've updated our dependency from V2 to V3 which will buy us another three weeks. While I would still very much appreciate an answer to my question, the urgency is no longer there, for me, at least. – Daen de Leon Apr 02 '15 at 23:08
  • Found this other answer: http://stackoverflow.com/questions/24185206/how-to-use-spreadsheetsservice-authenticated-by-serviceaccountcredential – Gerardo Apr 02 '15 at 23:51
  • 1
    Updating the GData core dependency fixed this -- it is at 1.47.1; ours was 1.41.5 ... – Daen de Leon Apr 17 '15 at 12:53
  • Oh, and a **really** critical step that isn't mentioned **anywhere** in any of these articles is that the service account email address has to be granted access to the spreadsheet, if it isn't public. That seems like such a crucial step that I am amazed that anyone has ever gotten this to work! – Daen de Leon Apr 17 '15 at 15:18
  • Excellent point with the 1.47.1 gdata. Thanks. I've been struggling with this for a while now. I still don't get why there is no comprehensive material to cover this issue. I think there are a lot of people who have been forced to migrate to oauth2 now. – davak Jun 16 '15 at 13:33

0 Answers0