Search code examples
phpzend-frameworkgdatagdata-apizend-gdata

Upload docs using zend gdata plugin


I am trying to upload a document into Google docs using the Zend_Gdata plugin. It uploads fine.

But the document by default becomes private. How can I set it to public. And how can I get the doc id and URL link to my doc so that others can access it to view only?

$service = Zend_Gdata_Docs::AUTH_SERVICE_NAME;
$client  = Zend_Gdata_ClientLogin::getHttpClient($email, $passwd, $service);
$docs    = new Zend_Gdata_Docs($client);
$feed    = $docs->getDocumentListFeed();

$newDocumentEntry = $docs->uploadFile(
    $filename, $name, null, Zend_Gdata_Docs::DOCUMENTS_LIST_FEED_URI
);

I appreciate any help.

Thanks


Solution

  • You must supply a different URI as the fourth parameter to the uploadFile() function, the one you're using will send docs to private. (Observe below)

    Check out the source code from Zend_Gdata_Docs.

    class Zend_Gdata_Docs extends Zend_Gdata
    {
        const DOCUMENTS_LIST_FEED_URI 
            = 'https://docs.google.com/feeds/documents/private/full';
        // ...
    

    As you can see, the class const is linking to a private path. Instead of using Zend_Gdata_Docs::DOCUMENTS_LIST_FEED_URI, you would have to use public. However, according to Google's Documents List Feed API, it appears they only accept private.

    The visibility parameter has two possible values: private and public.

    Note: Currently, private is the only visibility available in the Documents List API. For more information, see Visibility values, below.


    By the way, the end result should return a Zend_Gdata_App_Entry object to $newDocumentEntry with which I think you should be able to call functions like $newDocumentEntry->getEditLink() etc.

    If you want to see what else is stored in that object that do this:

    Zend_Debug::dump($newDocumentEntry);
    

    Good luck!