开发者

Get revisions of a spreadsheet with gdata Python api

I'm trying to get the revisions of a spreadsheet using the key, but it just returns "Invalid resource id".

from gdata.alt import appengine
from gdata.spreadsheet开发者_运维百科 import service
from gdata.docs.client import DocsClient

self.ss_svc = service.SpreadsheetsService()
# ... login code ...
gd_client = DocsClient(self.ss_svc.GetClientLoginToken())
rev_uri = "https://spreadsheets.google.com/feeds/spreadsheets/private/full/%s/revisions" % spreadsheet_key

# i also tried:
rev_uri = "spreadsheet%" + spreadsheet_key
rev_feed = gd_client.get(rev_uri)

Nothing works. Please help.


This code is a bit confusing because you refer to self but this doesn't appear to be part of a class definition. Also, you say you "also tried" gd_client.get(rev_uri) but I don't see what you tried before that -- no other method of gd_client is called in the above code. And finally, you're using the get method, which performs a http GET form request, which I don't think is what you want mean to do.

Seems like what you want is get_revisions. I'm just guessing -- let me know if this is mistaken.


Ok I figured this out, but not sure if the solution is completely right. Either way, it works.

class SpreadsheetLoader(object):  
  def __init__(self,config):
    from gdata.alt import appengine
    from gdata.spreadsheet import service
    from gdata.docs.client import DocsClient

    self.ss_svc = service.SpreadsheetsService()

    appengine.run_on_appengine(self.ss_svc, store_tokens=False, single_user_mode=True)
    self.ss_svc.email = config.dev_email
    self.ss_svc.password = config.dev_pwd
    self.ss_svc.source = 'Spreadsheet Loader'
    self.ss_svc.ProgrammaticLogin()

    feed = self.ss_svc.GetSpreadsheetsFeed(config.spreadsheet_key)

    # token = self.ss_svc.GetClientLoginToken()
    # gd_client = DocsClient(token)
    # token passing doesn't seem to work. It errors out with "str doesn't have some_method" :(
    # so I just login again... whatever.
    gd_client.client_login(config.dev_email, config.dev_pwd, "My App")

    resource_id = "spreadsheet:" + config.spreadsheet_key
    rev_feed = gd_client.get_revisions(resource_id)
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜