简体   繁体   English

带有 zend 的 Google 文档 API

[英]Google Docs API with zend

I'm trying to read a Doc from Google with an authorized user and output the content through my page.我正在尝试通过授权用户和 output 阅读来自 Google 的文档,并通过我的页面阅读内容。

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"一切正常,output 正常,但几秒钟后,弹出窗口 window 出现错误“Google 文档遇到错误。我们正在调查问题。请尝试以下临时解决方案之一:重新加载此页面”

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('MYUSER@gmail.com', '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.如果我尝试导出到 PDF 一切正常(我只需要更改链接),但我想像在 Google 文档中一样显示该页面。

Any help?有什么帮助吗? Best Regards DF最好的问候

You cannot output the HTML content of a Google Doc page into the context of your own page and get that to work.您不能将 Google 文档页面的内容 output HTML 放入您自己页面的上下文中并使其正常工作。 If you want to show a document to a user, redirect them to the Google Doc itself, using an HTTP Location header.如果您想向用户显示文档,请使用 HTTP 位置 header 将他们重定向到 Google 文档本身。

<?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.使用文档列表 API 将文档共享给用户。
  2. Export the document as text, HTML, or PDF using the API, and then display it to the user.使用 API 将文档导出为文本 HTML 或 PDF,然后将其显示给用户。

These options are detailed in the documentation .这些选项在文档中有详细说明。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM