0
votes

I'm trying to read a Doc from Google with an authorized user and output the content through my page.

Everything works fine, and the output is Ok, but after few seconds, a popup window appears with an error "Google Docs has encountered an error. We are looking into the problem now. Please try one of these interim solutions: Reload this page"

My code is this:

<?php
  require_once 'Zend/Loader.php';
  Zend_Loader::loadClass('Zend_Gdata_Docs');
  Zend_Loader::loadClass('Zend_Gdata_ClientLogin');
  Zend_Loader::loadClass('Zend_Gdata_Calendar');
  Zend_Loader::loadClass('Zend_Gdata_Docs_Query');

  $service = Zend_Gdata_Docs::AUTH_SERVICE_NAME;
  $client_grabmark = Zend_Gdata_ClientLogin::getHttpClient('[email protected]', 'MYPASS', $service);
  $service = new Zend_Gdata_Docs($client_grabmark); 
  $service->setMajorProtocolVersion(3);


  $contentLink = 'https://docs.google.com/document/d/'DOCID'/edit';

  $data = $service->get($contentLink)->getBody();

  ob_start();
  echo $data;
  ob_flush();
  exit  
?>

What I'm doing wrong? If I try export to PDF everything is Ok (I just have to change the link), but I want to show the page as if I was in Google Docs.

Any help? Best Regards DF

1

1 Answers

2
votes

You cannot output the HTML content of a Google Doc page into the context of your own page and get that to work. If you want to show a document to a user, redirect them to the Google Doc itself, using an HTTP Location header.

<?php
header("Location: $contentLink");
?>

If the user you had intended to display the doc to does not have permission to access the doc, there are two options:

  1. Share the doc to the user using the Documents List API.
  2. Export the document as text, HTML, or PDF using the API, and then display it to the user.

These options are detailed in the documentation.