我正在尝试使用google drive api在google驱动器中的特定文件夹中创建一个Google电子表格。所以,到目前为止,我已经编写了一个代码来创建一个电子表格,但不幸的是它没有用。
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有问题。我能得到任何帮助吗?
答案 0 :(得分:0)
CreateResource方法不接受类型参数,只有gdata.docs.data.Resource方法接受类型参数。如果你想研究那个转到this link。请参阅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)