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?
I found that document.GetId()
's returned value contains the key that we need. I don't know if it is the right way to get the key, but it works.
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)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With