2012-04-07 19 views
5

Google दस्तावेज़ एपीआई का उपयोग करके, मैं अपने दस्तावेज़ों के साथ-साथ अपने Google दस्तावेज़ों में किसी विशिष्ट फ़ोल्डर के भीतर सभी मौजूदा दस्तावेज़ों की एक सूची की आपूर्ति करने की कोशिश कर रहा हूं। मैं अजगर विकास के साथ शुरू कर रहा हूं, इसलिए मैं अभी भी किनारों के चारों ओर थोड़ा मोटा हूँ।Google डॉक्स एपीआई पाइथन

बातें मुझे क्या करना कोशिश कर रहा हूँ:

  1. नाम के साथ एक संग्रह (या फ़ोल्डर) बनाएं [फ़ोल्डर का नाम] कि नाम मौजूद नहीं है केवल यदि अभी तक
  2. अंदर कोई दस्तावेज़ बनाने [फ़ोल्डर का नाम]
  3. केवल से [फ़ोल्डर का नाम] दस्तावेजों की एक सूची लिंक के साथ स्वयं दस्तावेज़

के लिए मिलता है मेरा मानना ​​है कि मैं गूगल डॉक्स एपी उपयोग कर रहा हूँ मैं 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. मैं इस फ़ोल्डर में बनाए गए सभी दस्तावेज़ों के पूर्ण लिंक कैसे प्राप्त करूं?

मुझे पता है कि मैं यहां पूरा होने से मील दूर हूं, लेकिन आप जो भी मदद या सलाह दे सकते हैं वह बहुत अच्छा होगा।

अग्रिम धन्यवाद!

उत्तर

3

You can query for a folder or document। एक बार आपके पास फ़ोल्डर हो जाने पर आप इसकी सामग्री सूचीबद्ध कर सकते हैं।

# 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

अपने जवाब में जानकारी के लिए धन्यवाद: यहाँ पायथन पुस्तकालय के साथ एक उदाहरण है। वास्तव में इसकी सराहना करते हैं और मुझे लगता है कि मैं आपके उदाहरण के आधार पर काम करने के लिए शुरू कर रहा हूं। हालांकि प्रविष्टि। GetSelfLink()। Href मुझे इस प्रारूप में एक लिंक देता है: https: //docs.google.com/feeds/default/private/full/folder% .... जो, ब्राउज़र में उपयोग किए जाने पर, प्राप्त करें मैं "अमान्य अनुरोध यूआरआई" – user791793

संबंधित मुद्दे