Open yuhengh opened 9 years ago
Yeah, the API seems broken. Some of our script that uses the spreadsheet library fails as well.
These have not been updated in 4 years in some cases (the Contacts). It's a pity they have not fond time to update it in the 3 years since ClientLogin has been deprecated.
fwiw the problem is the combination of using the "new" oauth2 authentication, together with the "old" service spreadsheet api.
If instead, you use the newer client spreadsheet api, things seem to work. Thus, something along the following lines should work:
credentials = SignedJwt....
token = gdata.gauth.OAuth2TokenFromCredentials(credentials)
client = gdata.spreadsheets.client.SpreadsheetsClient()
client = token.authorize(client)
feed = client.get_spreadsheets()
print feed
I knew I need to use oauth2 to be able to do that. I tried to modify my script to this post http://stackoverflow.com/questions/16026286/using-oauth2-with-service-account-on-gdata-in-python
Then I got this error
Traceback (most recent call last): File "/Applications/PyCharm.app/helpers/pydev/pydevd.py", line 1733, in
debugger.run(setup['file'], None, None)
File "/Applications/PyCharm.app/helpers/pydev/pydevd.py", line 1226, in run
pydev_imports.execfile(file, globals, locals) # execute the script
File "/Users/tom/projects/jolu/mobile_framework/tools/config/test.py", line 24, in
feed = gd_client.GetWorksheetsFeed("11HnWT0tHZsRdSd4nY5gktoh0Jg3q_1XEy1Ig-JzfECk")
File "/Library/Python/2.7/site-packages/gdata/spreadsheet/service.py", line 129, in GetWorksheetsFeed
converter=gdata.spreadsheet.SpreadsheetsWorksheetsFeedFromString)
File "/Library/Python/2.7/site-packages/gdata/service.py", line 1069, in Get
headers=extra_headers)
File "/Library/Python/2.7/site-packages/atom/init.py", line 93, in optional_warn_function
return f(_args, *_kwargs)
File "/Library/Python/2.7/site-packages/atom/service.py", line 186, in request
data=data, headers=all_headers)
File "/Library/Python/2.7/site-packages/atom/http_interface.py", line 148, in perform_request
return http_client.request(operation, url, data=data, headers=headers)
TypeError: new_request() takes exactly 1 argument (4 given)
Here's my complete source code
import gdata.spreadsheet.service import gdata.service import gdata.spreadsheet import gdata.gauth from oauth2client.client import SignedJwtAssertionCredentials import httplib2
credentials = SignedJwtAssertionCredentials( "XXXXX@developer.gserviceaccount.com", open("secret.p12").read(), scope=( "https://www.googleapis.com/auth/drive", "https://spreadsheets.google.com/feeds", "https://docs.google.com/feeds" ), # For example. sub="user@gmail.com" ) http = httplib2.Http() http = credentials.authorize(http) auth2token = gdata.gauth.OAuth2TokenFromCredentials(credentials) gd_client = gdata.spreadsheet.service.SpreadsheetsService() # For example. gd_client = auth2token.authorize(gd_client)
feed = gd_client.GetWorksheetsFeed("MY_DOC_ID")
Any idea how to fix it? I googled it online and found no working solution so far. It would be nice to update the examples so it can work again. Thanks!