2012-05-10 40 views
7

tôi đã quản lý để tạo ra một bảng tính doc mới sử dụng đoạn mã sau:Tạo bảng tính mới (Google API/Python)

# Authorize 
client = gdata.docs.client.DocsClient(source='TestDoc') 
client.http_client.debug = False 
client.client_login(self.cfg.get('google', 'email'), self.cfg.get('google', 'password'), source='TestDoc', service='writely') 

# Create our doc 
document = gdata.docs.data.Resource(type='spreadsheet', title='Test Report') 
document = client.CreateResource(document) 

Đó là sự hiểu biết của tôi là bạn phải xác thực với dịch vụ bảng để thao tác bảng tính.

# Connect to spreadsheet API 
client = gdata.spreadsheet.service.SpreadsheetsService() 
client.email = self.cfg.get('google', 'email') 
client.password = self.cfg.get('google', 'password') 
client.source = 'TestDoc' 
client.ProgrammaticLogin() 

Câu hỏi của tôi là làm cách nào để lấy khóa bảng tính từ bước tạo đầu tiên ở trên để truy cập bảng tính đó bằng gdata.spreadsheet api?

+0

Tôi cũng đang tìm cách tạo bảng tính và sử dụng mã của bạn, tôi không thể đạt được. –

Trả lời

10

Tôi thấy rằng giá trị trả lại của document.GetId() chứa khóa mà chúng tôi cần. Tôi không biết nếu đó là cách đúng để lấy chìa khóa, nhưng nó hoạt động.

spreadsheet_key = document.GetId().split("%3A")[1] 
print "Key = %s" % spreadsheet_key 

#example of using this key 
w = client.AddWorksheet("Sheet 42", 5, 5, spreadsheet_key) 
Các vấn đề liên quan