La API de datos de Google Documents List API permite que las aplicaciones cliente suban documentos a Google Documents y los listen en forma de feeds de la API de datos de Google Data ("GData"). Su aplicación cliente puede solicitar una lista de los documentos de un usuario, y consultar el contenido de un documento existente.
Consulte http://code.google.com/apis/documents/overview.html para obtener más información sobre la API de Google Documents List API.
Puede obtener una lista de los documentos de Google de un usuario en particular usando
el método getDocumentListFeed() del servicio
docs. El servicio devolverá un objeto
Zend_Gdata_Docs_DocumentListFeed
que contiene una lista de documentos asociados con el usuario
autenticado.
$service = Zend_Gdata_Docs::AUTH_SERVICE_NAME; $client = Zend_Gdata_ClientLogin::getHttpClient($user, $pass, $service); $docs = new Zend_Gdata_Docs($client); $feed = $docs->getDocumentListFeed();
El objeto Zend_Gdata_Docs_DocumentListFeed resultante
representa la respuesta del servidor. Este feed contiene una lista de
objetos Zend_Gdata_Docs_DocumentListEntry
($feed->entries), cada uno de los cuales representa un único
documento de Google.
Puede crear un nuevo documento de Google subiendo un documento de procesamiento de texto, una hoja de cálculo o una presentación. Este ejemplo proviene del ejemplo interactivo Docs.php que viene con la biblioteca. Muestra cómo subir un archivo e imprimir información sobre el resultado devuelto por el servidor.
/**
* Upload the specified document
*
* @param Zend_Gdata_Docs $docs The service object to use for communicating
* with the Google Documents server.
* @param boolean $html True if output should be formatted for display in a
* web browser.
* @param string $originalFileName The name of the file to be uploaded. The
* MIME type of the file is determined from the extension on this file
* name. For example, test.csv is uploaded as a comma separated volume
* and converted into a spreadsheet.
* @param string $temporaryFileLocation (optional) The file in which the
* data for the document is stored. This is used when the file has been
* uploaded from the client's machine to the server and is stored in
* a temporary file which does not have an extension. If this parameter
* is null, the file is read from the originalFileName.
*/
function uploadDocument($docs, $html, $originalFileName,
$temporaryFileLocation) {
$fileToUpload = $originalFileName;
if ($temporaryFileLocation) {
$fileToUpload = $temporaryFileLocation;
}
// Upload the file and convert it into a Google Document. The original
// file name is used as the title of the document and the MIME type
// is determined based on the extension on the original file name.
$newDocumentEntry = $docs->uploadFile($fileToUpload, $originalFileName,
null, Zend_Gdata_Docs::DOCUMENTS_LIST_FEED_URI);
echo "New Document Title: ";
if ($html) {
// Find the URL of the HTML view of this document.
$alternateLink = '';
foreach ($newDocumentEntry->link as $link) {
if ($link->getRel() === 'alternate') {
$alternateLink = $link->getHref();
}
}
// Make the title link to the document on docs.google.com.
echo "<a href=\"$alternateLink\">\n";
}
echo $newDocumentEntry->title."\n";
if ($html) {echo "</a>\n";}
}
Puede buscar en la lista de documentos usando algunos de los parámetros de consulta estándar de la API de Google Data. Las categorías se usan para restringir el tipo de documento (documento de procesador de texto, hoja de cálculo) devuelto. La cadena de consulta de texto completo se usa para buscar en el contenido de todos los documentos. Puede encontrar información más detallada sobre los parámetros específicos de Documents List en la Guía de referencia de la API de datos de Documents List.
También puede solicitar un feed que contenga todos sus documentos de un tipo específico. Por ejemplo, para ver una lista de sus documentos de procesamiento de texto, realizaría una consulta por categoría de la siguiente manera.
$feed = $docs->getDocumentListFeed(
'http://docs.google.com/feeds/documents/private/full/-/document');
Para solicitar una lista de sus hojas de cálculo de Google, use la siguiente consulta por categoría:
$feed = $docs->getDocumentListFeed(
'http://docs.google.com/feeds/documents/private/full/-/spreadsheet');
Puede buscar en el contenido de los documentos usando un
Zend_Gdata_Docs_Query en su solicitud. Un objeto Query
puede usarse para construir el URI de la consulta, pasando el término de búsqueda
como parámetro. Aquí hay un método de ejemplo que consulta
la lista de documentos en busca de documentos que contengan la cadena de búsqueda:
$docsQuery = new Zend_Gdata_Docs_Query(); $docsQuery->setQuery($query); $feed = $client->getDocumentListFeed($docsQuery);