【问题标题】:Trouble retrieving a google docs presentation using curl and php使用 curl 和 php 检索 google 文档演示文稿时遇到问题
【发布时间】:2013-03-27 21:24:26
【问题描述】:

当我尝试通过 php 使用 curl 访问已发布的演示文稿时,我遇到了问题。普通文档可以通过 curl 访问,但不能通过演示文稿访问。我正在寻找使这种检索文档的方法起作用或找到替代方法。谷歌支持没有给我答案,建议堆栈溢出。

起初,尝试通过 curl 访问演示文稿给了我这个错误:

Secure Connection Failed

An error occurred during a connection to develop.willf-rtb-dev.switchsoft.com.

SSL received a record that exceeded the maximum permissible length.

(Error code: ssl_error_rx_record_too_long)

我在我的开发机器上为我的测试域添加了一个虚拟主机来启用 ssl。此虚拟主机以以下几行开头:

<VirtualHost *:443>
    SSLEngine on
    SSLCertificateFile    /etc/ssl/certs/ssl-cert-snakeoil.pem
    SSLCertificateKeyFile /etc/ssl/private/ssl-cert-snakeoil.key

添加此虚拟主机后,尝试通过 curl 访问演示文稿会将我重定向到此页面:

https://support.google.com/accounts/bin/answer.py?hl=en&answer=32050(由于我的 cookie 设置有问题,告诉我清除我的 cookie)

我的 curl 代码也写入了一个 cookie 文件——在尝试通过 curl 访问演示文稿后,该文件的内容如下。清除文件内容没有好处,告诉 curl 不要写入这个文件也没有好处。

# Netscape HTTP Cookie File
# http://curl.haxx.se/rfc/cookie_spec.html
# This file was generated by libcurl! Edit at your own risk.

#HttpOnly_.google.com    TRUE    /    FALSE    1380146248    NID    67=q47Xyj4FU2_uuYosZzvr_50-o2q9qD0PG8avG3oTg0s2qlmjzGFqT0UhWpwLOEt9TWqP1jf77npfX9OBebQ8fqn6ID7b4b-jBoFbyEbCFkrQhcBIKekLS1fQI-mLw3Pg

我的 php curl 代码如下所示:

$ch = curl_init();
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_SSLVERSION,3);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,3);

$cookieFile = TMP_DIRECTORY . '/curlcookies.txt';
if (!file_exists($cookieFile)) {
file_put_contents($cookieFile, '');
}
curl_setopt($ch, CURLOPT_COOKIESESSION, true);
curl_setopt($ch, CURLOPT_COOKIEFILE, $cookieFile);
curl_setopt($ch, CURLOPT_COOKIEJAR, $cookieFile);

curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (X11; Linux x86_64; rv:19.0) Gecko/20100101 Firefox/19.0 FirePHP/0.4");
curl_setopt($ch, CURLOPT_FOLLOWLOCATION,1);
curl_setopt($ch, CURLOPT_FAILONERROR, 1);

$result = curl_exec($ch);
curl_close($ch);
return $result;

我曾尝试使用这种风格的 url 来下载演示文稿的 html:

https://docs.google.com/feeds/download/presentations/Export?exportFormat=html&format=html&id=1RDANgsJWv841KvQUROKhyikTuwQGXC5Q1XFvXDwAfMw

这需要我登录,当我签名时它给了我这个错误:

Sorry, the file you have requested does not exist.

Please check the address and try again.

我在使用 exportFormat=pdf 时没有收到此错误 -- 只要我登录了它就可以工作,但这不是我需要的。

我还没有尝试使用它,但我在这里找到了一些可能值得研究的 php 代码:

https://developers.google.com/drive/manage-downloads

任何人在这个问题上可以给我的任何提示或帮助将不胜感激。

最好的问候

费雷尔

【问题讨论】:

  • 有什么想法吗?任何人?非常感谢。

标签: curl google-docs google-docs-api google-drive-api


【解决方案1】:

我认为问题在于您尝试将其导出为 HTML 的导出语句

https://docs.google.com/feeds/download/presentations/Export?exportFormat=html&format=html&id=1RDANgsJWv841KvQUROKhyikTuwQGXC5Q1XFvXDwAfMw

请注意,在 google 演示前端中,它只允许您导出为 pdf、pptx、txt、jpg、png、svg。

https://developers.google.com/google-apps/documents-list/v2/reference#ExportParameters

在 google 文档中,它还指出演示文稿的值仅如下:“pdf”、“png”和“ppt”。

【讨论】:

  • 嗨。非常感谢您的回复。阅读我最初的帖子,我认为我未能完全清楚地说明问题。目前我没有使用你上面描述的方法,而是我只是试图通过 curl 联系它的发布 URL 来访问发布的演示文稿:docs.google.com/presentation/d/…。您上面描述的方法是我想用作后备的方法。非常感谢您的帮助。
  • 我认为您尝试访问的 URL 只能通过浏览器访问。为了下载演示文稿,您应该尝试通过 curl 访问docs.google.com/feeds/download/presentations/…
猜你喜欢
  • 1970-01-01
  • 2011-06-30
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多