您能否提供一个Python示例来说明如何下载Google文档电子表格(gid
)?我不能。使用Python从Google Docs下载电子表格
我已经淘汰了API的版本1,2和3。我没有运气,我无法弄清楚他们已编译好的ATOM类似的API,gdata.docs.service.DocsService._DownloadFile
私有方法说我是未经授权的,我不想自己写一个完整的Google登录认证系统。由于沮丧,我正要刺伤自己。
我有几个电子表格,我想访问他们像这样:
username = '[email protected]'
password = getpass.getpass()
def get_spreadsheet(key, gid=0):
... (help!) ...
for row in get_spreadsheet('5a3c7f7dcee4b4f'):
cell1, cell2, cell3 = row
...
请救救我的脸。
更新1:我试过以下,但没有Download()
或Export()
组合似乎工作。 (Google文件DocsService
here)
import gdata.docs.service
import getpass
import os
import tempfile
import csv
def get_csv(file_path):
return csv.reader(file(file_path).readlines())
def get_spreadsheet(key, gid=0):
gd_client = gdata.docs.service.DocsService()
gd_client.email = '[email protected]'
gd_client.password = getpass.getpass()
gd_client.ssl = False
gd_client.source = "My Fancy Spreadsheet Downloader"
gd_client.ProgrammaticLogin()
file_path = tempfile.mktemp(suffix='.csv')
uri = 'http://docs.google.com/feeds/documents/private/full/%s' % key
try:
entry = gd_client.GetDocumentListEntry(uri)
# XXXX - The following dies with RequestError "Unauthorized"
gd_client.Download(entry, file_path)
return get_csv(file_path)
finally:
try:
os.remove(file_path)
except OSError:
pass
莫非[此](http://stackoverflow.com/questions/2925985/syntaxerror-using-gdata-python-client-to-access-google-book-search-data-api/3013945#3013945 )是你的问题? – sje397 2010-07-20 07:37:35
试过了 - 谢谢!似乎帮助我通过登录问题。 – 2010-07-30 05:37:59