5

Using Google Document API, I'm trying to create new documents as well as supplying a list of all current documents within a specific folder in my Google Documents. I am starting out with python development, so I'm a little rough around the edges still.

Things I am trying to do:

  1. Create a collection (or folder) with name [Folder Name] ONLY if that name does not exist yet
  2. Create a document inside [Folder Name]
  3. From only [Folder Name] get a list of documents along with links to the documents themselves

I believe I am using Google Docs API 3.0 and am using gdata-2.0.16 helper for python.

Code so far:

    import gdata.docs.data
    import gdata.docs.client

    class SampleConfig(object):
        APP_NAME = 'GDataDocumentsListAPISample-v1.0'
        DEBUG = False

    client = gdata.docs.client.DocsClient()
    client.ClientLogin('[email_address]','[password]',source=SampleConfig.APP_NAME )

    col = gdata.docs.data.Resource(type='folder', title='Folder Name')
    col = client.CreateResource(col)

    doc = gdata.docs.data.Resource(type='document', title='I did this')
    doc = client.CreateResource(doc, collection=col)

So now on to the questions: Where I am hopelessly stuck:

  1. How do I check if [Folder name] exists?
  2. How to retrieve the contents of ONLY [Folder Name]?
  3. How do I get hold of absolute links to all documents I create in this folder?

I know I'm miles away from completion here, but any help or advice you could give would be great.

Thanks in advance!

1 Answer 1

3

You can query for a folder or document. Once you have the folder you can list its contents. Here is an example with the Python library:

# Create a query matching exactly a title, and include collections
q = gdata.docs.client.DocsQuery(
    title='EFD',
    title_exact='true',
    show_collections='true'
)

# Execute the query and get the first entry (if there are name clashes with
# other folders or files, you will have to handle this).
folder = client.GetResources(q=q).entry[0]

# Get the resources in the folder
contents = client.GetResources(uri=folder.content.src)

# Print out the title and the absolute link
for entry in contents.entry:
    print entry.title.text, entry.GetSelfLink().href

Output

My posted doc https://docs.google.com/...
subtestcoll2 https://docs.google.com/...
guestimates_1 https://docs.google.com/...
phase 2 delivery plan - draft https://docs.google.com/...
Meeting agenda June 09 https://docs.google.com/...
Phase 2 spec for Graeme 2 March 2009 https://docs.google.com/...
EFD Meeting 2nd June https://docs.google.com/...
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks for the details in your answer. Really appreciate it and I think I'm starting to get mine to work based on your example. However entry.GetSelfLink().href gives me a link in the format of: docs.google.com/feeds/default/private/full/folder%.... Which, when used in a browser, get's me "Invalid request URI"

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.