Retrieving Documents in Shared Folder via PHP

1,051 views
Skip to first unread message

Leo Brown

unread,
Dec 21, 2009, 9:48:54 AM12/21/09
to Google Documents List API
Hi

My application is to build a help system in Google Docs using a single
folder that is 'shared' to my external server-side renderer.

Ideally, I would give my server-side app the 'public' URI to the
folder containing all the folders and documents in the help system.
Alternatively, I would log in with an authenticated account and find
these documents.

The best progress I have made uses the Google Documents List API. I
have logged in, and can enumerate the files. Using the 'category' I
can at least find out their parent folder (one level deep).

However, I now need to retrieve their HTML content. I can get the URL
of the file, and change this to return HTML content, however the links
returned by Google Docs List Data API are not the 'public' links but
the link to edit the document with an authenticated account.

If you could shed any light on how best to approach this, I'd be
grateful, as I've been trying to solve it for some time!

Leo

Eric Bidelman

unread,
Dec 21, 2009, 10:36:14 AM12/21/09
to google-docum...@googlegroups.com
Are you talking about the link that points to the document
in Google Docs?  If so, that's the <link rel='alternate'..>

If you're talking about the published link (for documents
that are published and publicly accessible without credentials),
then you'll have to construct that link manually. The API doesn't
support querying for or discovering which documents have been
published. That's actually one of the most requested features:

Eric

Leo Brown

unread,
Dec 21, 2009, 10:52:31 AM12/21/09
to google-docum...@googlegroups.com
Unless there is a way to programmatically retrieve the HTML (which I hoped/assumed there was) then I was suggesting the Published URI would be the alternative. However, this is essentially a GUID and there would be no way of manually recreating it that I am aware of.

Surely it would be common practise not just to receive a list of documents, but the documents themselves?

Leo
 

Eric Bidelman

unread,
Dec 21, 2009, 10:57:01 AM12/21/09
to google-docum...@googlegroups.com
Very possible (with v3 of the API). See the protocol guide:

Leo Brown

unread,
Dec 21, 2009, 11:15:36 AM12/21/09
to google-docum...@googlegroups.com
Eric,

Thanks for that - what I did is this:

1. Used the docs list API to get the "alternate" URI.
2. Took the docID from this URI using regex
3. Used getDocument() from the Zend API (didn't work)
4. Manually called the relevant feed URL using Zend's process

   return $docs->getDocumentListEntry($location);

What happens next is very strange - I am seeing the writely CSS and HTML (even the document's HTML that I wanted), but before the content is ready finished it errors out with the following:

Fatal error: Uncaught exception 'Zend_Gdata_App_Exception' with message 'DOMDocument cannot parse XML: ' in /usr/acumen/production/netfuse.org/lib/Zend/Gdata/App.php:811 Stack trace: #0 /usr/acumen/production/netfuse.org/lib/Zend/Gdata/App.php(775): Zend_Gdata_App::importString('??importUrl('http://docs.goo...', 'Zend_Gdata_Docs...', NULL) #2 /usr/acumen/production/netfuse.org/lib/Zend/Gdata.php(187): Zend_Gdata_App->getEntry('http://docs.goo...', 'Zend_Gdata_Docs...') #3 /usr/acumen/production/netfuse.org/lib/Zend/Gdata/Docs.php(130): Zend_Gdata->getEntry('http://docs.goo...', 'Zend_Gdata_Docs...') #4 /usr/acumen/production/netfuse.org/app/controllers/knowledgebase_controller.php(57): Zend_Gdata_Docs->getDocumentListEntry('http://docs.goo...') #5 /usr/acumen/production/netfuse.org/cake/libs/object.php(117): KnowledgebaseController->view('1') #6 /usr/acumen/production/netfuse.org/cake/dis in /usr/acumen/production/netfuse.org/lib/Zend/Gdata/App.php on line 811

It appears to come just after the BODY and HTML tags have closed. Any idea why it might be baulking on this?

Cheers,
Leo

Leo Brown

unread,
Dec 21, 2009, 11:15:58 AM12/21/09
to google-docum...@googlegroups.com
Eric,

Thanks for that - what I did is this:

1. Used the docs list API to get the "alternate" URI.
2. Took the docID from this URI using regex
3. Used getDocument() from the Zend API (didn't work)
4. Manually called the relevant feed URL using Zend's process

   return $docs->getDocumentListEntry($location);

What happens next is very strange - I am seeing the writely CSS and HTML (even the document's HTML that I wanted), but before the content is ready finished it errors out with the following:

Fatal error: Uncaught exception 'Zend_Gdata_App_Exception' with message 'DOMDocument cannot parse XML: ' in /usr/acumen/production/netfuse.org/lib/Zend/Gdata/App.php:811 Stack trace: #0 /usr/acumen/production/netfuse.org/lib/Zend/Gdata/App.php(775): Zend_Gdata_App::importString('??importUrl('http://docs.goo...', 'Zend_Gdata_Docs...', NULL) #2 /usr/acumen/production/netfuse.org/lib/Zend/Gdata.php(187): Zend_Gdata_App->getEntry('http://docs.goo...', 'Zend_Gdata_Docs...') #3 /usr/acumen/production/netfuse.org/lib/Zend/Gdata/Docs.php(130): Zend_Gdata->getEntry('http://docs.goo...', 'Zend_Gdata_Docs...') #4 /usr/acumen/production/netfuse.org/app/controllers/knowledgebase_controller.php(57): Zend_Gdata_Docs->getDocumentListEntry('http://docs.goo...') #5 /usr/acumen/production/netfuse.org/cake/libs/object.php(117): KnowledgebaseController->view('1') #6 /usr/acumen/production/netfuse.org/cake/dis in /usr/acumen/production/netfuse.org/lib/Zend/Gdata/App.php on line 811

It appears to come just after the BODY and HTML tags have closed. Any idea why it might be baulking on this?

Cheers,
Leo

Leo Brown

unread,
Dec 21, 2009, 11:25:49 AM12/21/09
to google-docum...@googlegroups.com
Eric,

I realised I'm trying to parse a HTML response as an XML document list.

Correcting that, I simply used the get() function. My return object though only has protected properties, though I want to read the 'body' element. Do you know the right way of going around this?

[Response Object follows]

Cheers,
Leo

Zend_Http_Response Object
(
    [version:protected] => 1.1
    [code:protected] => 200
    [message:protected] => OK
    [headers:protected] => Array
        (
            [Content-type] => text/html; charset=UTF-8
            [Content-disposition] => attachment; filename="Porting_Numbers.html"
            [Date] => Mon, 21 Dec 2009 16:23:31 GMT
            [Expires] => Mon, 21 Dec 2009 16:23:31 GMT
            [Cache-control] => private, max-age=0
            [X-content-type-options] => nosniff
            [X-xss-protection] => 0
            [X-frame-options] => SAMEORIGIN
            [Connection] => close
            [Server] => GFE/2.0
            [Transfer-encoding] => chunked
        )

    [body:protected] => fef
Porting numbers...
)

Eric Bidelman

unread,
Dec 21, 2009, 11:33:55 AM12/21/09
to google-docum...@googlegroups.com
Reply all
Reply to author
Forward
0 new messages