7

I've managed to create a new spreadsheet doc using the following code:

# 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)

It is my understanding that you have to authenticate with the spreadsheet service in order to manipulate a spreadsheet.

# 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()

My question is how do I obtain the spreadsheet key from the creation in the first step above in order to access that spreadsheet with the gdata.spreadsheet api?

4

1 に答える 1

10

document.GetId()の戻り値に必要なキーが含まれていることがわかりました。キーを取得する正しい方法かどうかはわかりませんが、機能します。

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)
于 2012-05-13T10:45:31.210 に答える