I’m utilizing the Google Docs API to generate new documents and list all existing documents within a designated folder in my Google Drive. As I’m a beginner in Python development, I encounter some challenges.
Objectives I want to achieve:
- Create a folder named [Folder Name] only if it doesn’t already exist.
- Add a new document inside the [Folder Name].
- Retrieve a list of all documents within the [Folder Name], including their direct links.
I’m currently using version 3.0 of the Google Docs API along with the gdata-2.0.16 library for Python.
Here’s my current code:
import gdata.docs.data
import gdata.docs.client
class SampleConfig(object):
APP_NAME = 'GDataDocsAPISample-v1.0'
DEBUG = False
client = gdata.docs.client.DocsClient()
client.ClientLogin('[email_address]', '[password]', source=SampleConfig.APP_NAME)
folder = gdata.docs.data.Resource(type='folder', title='Folder Name')
folder = client.CreateResource(folder)
document = gdata.docs.data.Resource(type='document', title='Sample Document')
document = client.CreateResource(document, collection=folder)
I have a few questions I’m struggling with:
- How can I verify if [Folder Name] is already created?
- What is the method to list contents exclusively from [Folder Name]?
- How can I obtain direct links for all documents created in this folder?
I’m eager for any guidance or tips you can offer. Thank you!