简体   繁体   English

在驱动器中的特定文件夹中创建Google电子表格 谷歌驱动器api

[英]create google spreadsheet in specific folder in drive | Google drive api

I am trying to create a google spreadsheet in specific folder in google drive with the google drive api. 我正在尝试使用google驱动器API在谷歌驱动器中的特定文件夹中创建一个谷歌电子表格。 So, far I have written a code to just create a spreadsheet but unfortunately it is not working. 所以,到目前为止,我已经编写了一个代码来创建一个电子表格,但不幸的是它没有用。

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

But this is throwing error in the line newDocument = client.CreateResource(document, type = "spreadsheet", create_uri=gdata.docs.client.RESOURCE_FEED_URI) 但这是在行newDocument = client.CreateResource(document, type = "spreadsheet", create_uri=gdata.docs.client.RESOURCE_FEED_URI)抛出错误

Error Traceback: 错误回溯:

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'

I guess there is something wrong with create_uri. 我猜create_uri有问题。 Can I get any help? 我能得到任何帮助吗?

The CreateResource method does not take a type argument, only the gdata.docs.data.Resource method takes a type argument. CreateResource方法不接受类型参数,只有gdata.docs.data.Resource方法接受类型参数。 If you would like to look into that go to this link . 如果您想查看,请转到此链接 Refer to the gdata API in order to get a better understanding of CreateResource() and its arguments. 请参阅gdata API以便更好地理解CreateResource()及其参数。

Here is how I set up creating the document: 以下是我设置文档的方法:

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM