2012-04-07 13 views
5

GoogleドキュメントAPIを使用して、私は新しいドキュメントを作成し、私のGoogleドキュメント内の特定のフォルダ内のすべての現在のドキュメントのリストを提供しようとしています。私はPythonの開発から始めているので、まだまだ少し荒いです。私がやろうとしていますGoogle Docs API with Python

もの:

  1. その 名前はまだ
  2. は、[フォルダ名]の内部文書を作成して存在しない場合にのみ、[フォルダ名]名前のコレクション(またはフォルダ)を作成します。
  3. のみ[フォルダ名]から、私はGoogle DocsのAPを使用しています信じているドキュメント自体

を へのリンクと一緒にドキュメントのリストを取得します私は3.0を使用していますgdata-2.0.16の助けを借りています。これまで

コード:

 

    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) 

だから今の質問に:私は絶望的に立ち往生しています:[フォルダ名]が存在する場合、私がチェックするにはどうすればよい

  1. [フォルダ名]のみの内容を取得するにはどうすればよいですか?
  2. このフォルダに作成するすべてのドキュメントへの絶対リンクを保持するにはどうすればよいですか?

私はここから完成まで数マイル離れていることは分かっていますが、助けてくれれば助かります。

ありがとうございます!

答えて

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/... 
+0

感謝。本当にそれを感謝し、私はあなたの例に基づいて私の仕事を開始していると思う。しかし、entry.GetSelfLink()。hrefは私にhttps://docs.google.com/feeds/default/private/full/folder%の形式のリンクを与えます。ブラウザで使用するとget、私は "無効なリクエストURI" – user791793