2012-05-10 31 views
7

を作成し、私は次のコードを使用して新しいスプレッドシートドキュメントを作成するために管理してきました:新しいスプレッドシート(​​のGoogle API /パイソン)

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

それはあなたのために、スプレッドシートのサービスで認証する必要が私の理解ですスプレッドシートを操作する。

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

私の質問は、私は上記のgdata.spreadsheet APIでそのスプレッドシートにアクセスするために、第1のステップで作成からスプレッドシートキーを取得しますどのようにでしょうか?

+0

また、スプレッドシートを作成しようとしていて、コードを使用しても達成できません。 –

答えて

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) 
関連する問題