Bạn có thể tạo ví dụ về cách tải xuống bảng tính Google Tài liệu bằng ID khóa và trang tính của mình (gid
) không? Tôi không thể.Tải xuống bảng tính từ Google Documents bằng cách sử dụng Python
Tôi đã xóa các phiên bản 1, 2 và 3 của API. Tôi không có may mắn, tôi không thể tìm ra API nguồn cấp dữ liệu giống như ATOM, phương pháp riêng gdata.docs.service.DocsService._DownloadFile
nói rằng tôi không được phép và tôi không muốn tự mình viết toàn bộ hệ thống xác thực đăng nhập của Google. Tôi chuẩn bị đâm vào mặt vì sự thất vọng.
Tôi có một vài bảng tính và tôi muốn để truy cập chúng như vậy:
username = '[email protected]'
password = getpass.getpass()
def get_spreadsheet(key, gid=0):
... (help!) ...
for row in get_spreadsheet('5a3c7f7dcee4b4f'):
cell1, cell2, cell3 = row
...
hãy giữ thể diện của tôi.
Cập nhật 1: Tôi đã thử những điều sau đây, nhưng không có sự kết hợp của Download()
hoặc Export()
dường như làm việc. (Documents cho 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
Could [này] (http://stackoverflow.com/questions/2925985/syntaxerror-using-gdata-python-client-to-access-google-book-search-data-api/3013945#3013945) là vấn đề của bạn? – sje397
Đã thử - cảm ơn! Dường như giúp tôi giải quyết vấn đề đăng nhập trong quá khứ. –