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:
- This does NOT work if I use
gdata.spreadsheet.service.SpreadsheetsService()
, but does work withgdata.spreadsheets.client.SpreadsheetsClient()
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!
script_dir = os.path.dirname(os.path.realpath (sys.argv[0])) private_key = open(script_dir + "\\IntReqCreds.pem").read()
– Pete Segal Dec 22 '14 at 20:06