简体   繁体   中英

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

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. 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. 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.

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) 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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