0

I'm using Python 2.7 and the client library for Google API which I am trying to use to get authenticated access to Spreadsheets like so:

# sa == Service Account
scope = 'https://spreadsheets.google.com/feeds'
credentials = SignedJwtAssertionCredentials(sa_id, sa_key, scope)
http = httplib2.Http()
http = credentials.authorize(http)
build('spreadsheets', 'v2', http=http)

Note this is from a client script and not in Google App Engine. The output of the above is:

File "/Library/Python/2.7/site-packages/apiclient/discovery.py", line 196, in build version)) apiclient.errors.UnknownApiNameOrVersion: name: spreadsheets version: v2

I know I'm doing this wrong, but I'm having trouble finding any examples of authenticating without using ClientLogin and/or the .NET/Java client libraries.

[UPDATE] The answer may be in the following source example, but I noticed on skimming it that it still uses email/password: https://code.google.com/p/gdata-python-client/source/browse/src/gdata/spreadsheet/service.py

1
  • Did you read the big red box at the top of your second link? The one that says that api versions 1 and 2 are no longer available? Commented Jan 30, 2014 at 21:16

1 Answer 1

2

The old Python gdata service libraries support ClientLogin, AuthSub and OAuth 1.0 authentication. All of which have been deprecated. If you wish to use the OAuth 2.0 Service Account credentials you'll need to hack something together like:

def buildSpreadsheetService():
  scope = 'https://spreadsheets.google.com/feeds'
  credentials = SignedJwtAssertionCredentials(sa_id, sa_key, scope)
  http = httplib2.Http()
  http = credentials.authorize(http)
  build('drive', 'v2', http=http)
  sheets = gdata.spreadsheet.service.SpreadsheetsService()
  sheets.additional_headers = {'Authorization': 'Bearer %s' % http.request.credentials.access_token}
  return sheets
Sign up to request clarification or add additional context in comments.

3 Comments

Hello again, Jay! Unfortunately without the call to build(), the http.request.credentials.access_token is None. My question is specifically around that line because once I get past it I can then pass that http object as per the other question you answered (stackoverflow.com/questions/21420777/…).
edited to add build('drive', 'v2', http=http) which should leave http with a valid access token.
I tried this and am getting a 403 Access Denied response when I try to update a cell. I've enabled Drive API for the app. Any ideas about why this could be?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.