![](/img/trans.png)
[英]Python - Using gspread to create a spreadsheet in a specific folder in Google Drive
[英]create google spreadsheet in specific folder in drive | Google drive api
我正在嘗試使用google驅動器API在谷歌驅動器中的特定文件夾中創建一個谷歌電子表格。 所以,到目前為止,我已經編寫了一個代碼來創建一個電子表格,但不幸的是它沒有用。
import gdata.docs.client
import gdata.docs.data
# Authorize
client = gdata.docs.client.DocsClient(source='sixact')
client.api_version = "3"
client.ssl = True
client.client_login(EMAIL, PASSWORD, client.source)
# Create our doc
document = gdata.docs.data.Resource(type='spreadsheet', title='Test Report')
newDocument = client.CreateResource(document, type = "spreadsheet", create_uri=gdata.docs.client.RESOURCE_FEED_URI)
spreadsheet_key = newDocument.GetId().split("%3A")[1]
print "Key = %s" % spreadsheet_key
但這是在行newDocument = client.CreateResource(document, type = "spreadsheet", create_uri=gdata.docs.client.RESOURCE_FEED_URI)
拋出錯誤
錯誤回溯:
Traceback (most recent call last):
File "E:\coding\FL\ongoing jobs\Expert python-django\test\sixact\create.py", line 17, in <module>
newDocument = client.CreateResource(document, type = "spreadsheet", create_uri=gdata.docs.client.RESOURCE_FEED_URI)
File "E:\coding\FL\ongoing jobs\Expert python-django\test\sixact\gdata\docs\client.py", line 307, in create_resource
entry, create_uri, desired_class=gdata.docs.data.Resource, **kwargs)
File "E:\coding\FL\ongoing jobs\Expert python-django\test\sixact\gdata\client.py", line 686, in post
entry.to_string(get_xml_version(self.api_version)),
File "E:\coding\FL\ongoing jobs\Expert python-django\test\sixact\atom\core.py", line 352, in to_string
tree_string = ElementTree.tostring(self._to_tree(version, encoding))
AttributeError: 'module' object has no attribute 'tostring'
我猜create_uri有問題。 我能得到任何幫助嗎?
CreateResource方法不接受類型參數,只有gdata.docs.data.Resource方法接受類型參數。 如果您想查看,請轉到此鏈接 。 請參閱gdata API以便更好地理解CreateResource()及其參數。
以下是我設置文檔的方法:
document = gdata.docs.data.Resource(type='spreadsheet',
title= spreadtitle) #spreadtitle = "whatever"
document = gd_client.CreateResource(document,
create_uri=gdata.docs.client.RESOURCE_FEED_URI)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.