Please confirm: SignedJwtAssertionCredentials only works with SpreadsheetsClient, not SpreadsheetsService?

383 Views Asked by At

After a week of Googling and trial & error, I finally got my Python script that adds a row to a Google spreadsheet to work with OAuth2. For the benefit of others who may suffer the same trauma, here's my working code:

script_dir  = os.path.dirname(os.path.realpath (sys.argv[0]))
private_key = open(script_dir + "\\myClient.pem").read()
ssClient    = gdata.spreadsheets.client.SpreadsheetsClient()

credentials = SignedJwtAssertionCredentials(CLIENT_EMAIL, private_key, SCOPE)
http        = Http()
http        = credentials.authorize(http)
auth2token  = gdata.gauth.OAuth2TokenFromCredentials(credentials)
ssClient    = auth2token.authorize(ssClient)

ssClient.GetSpreadsheets()

Two notes:

  1. This does NOT work if I use gdata.spreadsheet.service.SpreadsheetsService(), but does work with gdata.spreadsheets.client.SpreadsheetsClient()
  2. This does NOT work using the .p12 files downloaded from the Google Developer Console, I needed to convert it to a .pem file with:

    openssl pkcs12 -nodes -nocerts -in myClient.p12 -out myClient.pem
    

Could someone please confirm that there is indeed no way to use SignedJwtAssertionCredentials with SpreadsheetsService, or if there is, please explain the correct procedure? I've pretty much tried every combination I could think of.

Thanks!

1

There are 1 best solutions below

1
On

I feel your pain, have spent a full day trying to get my old gdata.spreadsheet.service code to work with oauth2client.client.SignedJwtAssertionCredentials and still have not managed to get it working. It does not work for me with SpreadsheetsClient or SpreadsheetsService, nor when converting the .p12 to .pem. It looks like it works, (no auth error messages) but when doing for example a GetSpreadsheets() call I get an empty result.

Could not find any good examples of hooking up the old gdata code to oauth, your snippet above was the clearest to be found so far. The struggle continues.