使用Google Document API,我正在尝试创建新文档,并在我的Google文档中提供特定文件夹中所有当前文档的列表。我开始使用python开发,所以我仍然有点粗糙。
我想做的事情:
我相信我正在使用Google Docs API 3.0并且正在使用 gdata-2.0.16 帮助python。
到目前为止代码:
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)
现在回答问题:我无可救药地陷入困境:
我知道我离这里已经很远了,但是你能给予的任何帮助或建议都会很棒。
提前致谢!
答案 0 :(得分:3)
You can query for a folder or document。获得文件夹后,您可以列出其内容。以下是Python库的示例:
# 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
输出
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/...