我正在尝试使用密钥获取电子表格的修订版,但它只返回“无效的资源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)
没有任何作用。请帮忙。
答案 0 :(得分:1)
这段代码有点令人困惑,因为你引用了self
,但这似乎不是类定义的一部分。另外,你说你“也试过”gd_client.get(rev_uri)
但我没看到你之前尝试过的东西 - 在上面的代码中没有调用gd_client
的其他方法。最后,您正在使用get
方法,该方法执行http GET表单请求,我不会认为是您想要做的事情。
似乎你想要的是get_revisions
。我只是猜测 - 让我知道这是不是错了。
答案 1 :(得分:0)
好的,我想出来了,但不确定解决方案是否完全正确。无论哪种方式,它都有效。
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)