需要帮助:阅读我的 Google 电子表格,并将其保密

发布于 2024-09-15 05:55:26 字数 2553 浏览 2 评论 0原文

试图让这个工作变得非常沮丧。基本上这是一个网站(x10hosting.com),我无法包含 zend gdata 框架,所以我尝试使用 Google Data API 和 php cURL 来访问它。我能做的最多的事情就是使用此脚本返回所提供的用户名工作表的列表:

<?php

// Construct an HTTP POST request
$clientlogin_url = "https://www.google.com/accounts/ClientLogin";
$clientlogin_post = array(
    "accountType" => "HOSTED_OR_GOOGLE",
    "Email" => "", //username
    "Passwd" => '',  //password
    "service" => "writely",
    "source" => "your application name"
);

// Initialize the curl object
$curl = curl_init($clientlogin_url);

// Set some options (some for SHTTP)
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, $clientlogin_post);
curl_setopt($curl, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);

// Execute
$response = curl_exec($curl);

// Get the Auth string and save it
preg_match("/Auth=([a-z0-9_\-]+)/i", $response, $matches);
$auth = $matches[1];

echo "The auth string is: ".$auth;
// Include the Auth string in the headers
// Together with the API version being used
$headers = array(
    "Authorization: GoogleLogin auth=".$auth,
    "GData-Version: 3.0",
);

// Make the request
$key = ;
curl_setopt($curl, CURLOPT_URL, "https://spreadsheets1.google.com/ccc?key=$key");
curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
curl_setopt($curl, CURLOPT_POST, false);

$response = curl_exec($curl);
curl_close($curl);
var_dump($response);
// Parse the response
$response = simplexml_load_string($response);

// Output data
foreach($response->entry as $file)
{
    echo "File: " . $file->title . "<br />";
    echo "Type: " . $file->content["type"] . "<br />";
    echo "Author: " . $file->author->name . "<br /><br />";
}
?>

但我无法找到一种方法来使用它来访问一个特定的工作表。请帮忙,这让我发疯。

编辑:遵循 DASPRiD 的建议给了我这个错误 ->

注意: Zend_Loader::Zend_Loader::registerAutoload 从 1.8.0 开始已被弃用,并将 2.0.0 中删除;使用 Zend_Loader_Autoloader 改为 /home/c3webdev/public_html/library/Zend/Loader.php 在第266行

警告: require_once(Zend/Loader/Autoloader.php) [function.require-once]:未能 打开流:没有这样的文件或目录 在 /home/c3webdev/public_html/library/Zend/Loader.php 在第 267 行

致命错误:require_once() [function.require]: 打开失败 需要“Zend/Loader/Autoloader.php” (include_path='/home/c3webdev/public_html/library:.:/usr/lib/php:/usr/local/lib/php') 在 /home/c3webdev/public_html/library/Zend/Loader.php 在第 267 行

Getting super frustrated trying to get this working. Basically this is for a site (x10hosting.com) where I can't include the zend gdata framework, so I'm trying to use the Google Data API with php cURL to access it. The most I've been able to do is return a list of the supplied usernames worksheets, using this script:

<?php

// Construct an HTTP POST request
$clientlogin_url = "https://www.google.com/accounts/ClientLogin";
$clientlogin_post = array(
    "accountType" => "HOSTED_OR_GOOGLE",
    "Email" => "", //username
    "Passwd" => '',  //password
    "service" => "writely",
    "source" => "your application name"
);

// Initialize the curl object
$curl = curl_init($clientlogin_url);

// Set some options (some for SHTTP)
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, $clientlogin_post);
curl_setopt($curl, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);

// Execute
$response = curl_exec($curl);

// Get the Auth string and save it
preg_match("/Auth=([a-z0-9_\-]+)/i", $response, $matches);
$auth = $matches[1];

echo "The auth string is: ".$auth;
// Include the Auth string in the headers
// Together with the API version being used
$headers = array(
    "Authorization: GoogleLogin auth=".$auth,
    "GData-Version: 3.0",
);

// Make the request
$key = ;
curl_setopt($curl, CURLOPT_URL, "https://spreadsheets1.google.com/ccc?key=$key");
curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
curl_setopt($curl, CURLOPT_POST, false);

$response = curl_exec($curl);
curl_close($curl);
var_dump($response);
// Parse the response
$response = simplexml_load_string($response);

// Output data
foreach($response->entry as $file)
{
    echo "File: " . $file->title . "<br />";
    echo "Type: " . $file->content["type"] . "<br />";
    echo "Author: " . $file->author->name . "<br /><br />";
}
?>

But I can't figure out a way to use this to access one specific worksheet. Please help, this is driving me nuts.

EDIT: Following DASPRiD's advice gives me this error->

Notice:
Zend_Loader::Zend_Loader::registerAutoload is deprecated as of 1.8.0 and will be
removed with 2.0.0; use
Zend_Loader_Autoloader instead in
/home/c3webdev/public_html/library/Zend/Loader.php
on line 266

Warning:
require_once(Zend/Loader/Autoloader.php)
[function.require-once]: failed to
open stream: No such file or directory
in
/home/c3webdev/public_html/library/Zend/Loader.php
on line 267

Fatal error: require_once()
[function.require]: Failed opening
required 'Zend/Loader/Autoloader.php'
(include_path='/home/c3webdev/public_html/library:.:/usr/lib/php:/usr/local/lib/php')
in
/home/c3webdev/public_html/library/Zend/Loader.php
on line 267

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

随风而去 2024-09-22 05:57:01

对于一个非常简单的替代解决方案没有 Zend 和 Google API,这也可能有所帮助。

您可以将 Google 电子表格以 csv 形式发布在网络上(使用私有 URL),然后只需通过 fopen/fgetcsv 访问它:

https://stackoverflow.com/a/18106727/1300348

请注意,没有身份验证...因此,无论谁拥有您的网址,都拥有您的数据,因此对于以下位置的文件来说,这可能不是正确的解决方案其中包含密码。
但也许它可以帮助有类似问题的人。

For a really easy alternative solution without Zend and without Google API this may also help.

You can publish your Google Spreadsheet as csv on the web (with a private URL) and simply access it by fopen/fgetcsv:

https://stackoverflow.com/a/18106727/1300348

Please be aware there is no authentication... so whoever has your url has your data, hence this might not be the right solution for files where there are passwords included.
But maybe it helps someone with a similar problem.

凶凌 2024-09-22 05:56:53

一旦您获得了为该用户提供的工作表列表,您就可以解析以获取数据(这就是您想要的,对吗?工作表数据?)

如上所述,这就是您获取可用电子表格的方式

http://spreadsheets.google.com/feeds/worksheets/<spreadsheet-key>/private/full

然后从那里您可以获取网址到特定的电子表格,然后从那里您可以从中获取数据列表

返回带有适当标题的数据

https://spreadsheets.google.com/feeds/list/<spreadsheet-key>/<worksheet-id>/private/basic

单元格返回带有定义的单元格(A1,C23等)

https://spreadsheets.google.com/feeds/cells/0<spreadsheet-key>/<worksheet-id>/private/basic

的更多信息 。 code.google.com/apis/spreadsheets/data/3.0/developers_guide_protocol.html#ListingSpreadsheets" rel="nofollow noreferrer">Google 电子表格 API 参考

Once you get the list of supplied worksheets for that user you can parse through to get the data (thats what you want right? the worksheet data?)

As mentioned above this is how you get the spreadsheets available

http://spreadsheets.google.com/feeds/worksheets/<spreadsheet-key>/private/full

Then from there you can get the url to a specific spreadsheet and then from there you can get the data from that

List returns the data with appropriate headings

https://spreadsheets.google.com/feeds/list/<spreadsheet-key>/<worksheet-id>/private/basic

Cells returns it with defined cells (A1, C23 etc.)

https://spreadsheets.google.com/feeds/cells/0<spreadsheet-key>/<worksheet-id>/private/basic

Here is more info on the google spreadsheets api reference

梅窗月明清似水 2024-09-22 05:56:44

对以下 URL 的查询应列出特定电子表格的所有工作表:

http://spreadsheets.google.com/feeds/worksheets/**spreadsheetKey**/private/full

要安装和使用 Zend_Gdata,请执行以下操作:

下载最后一个包 (http://framework.zend.com/releases/ZendGdata-1.10.7/ZendGdata-1.10.7.ta​​r.gz) 来自 Zend Framework 网站。现在让我们假设以下目录结构:

  • /index.php (您的主文件)
  • /library/Zend (在此处提取library/Zend 文件夹)

现在在您的index.php 中,执行以下操作:

set_include_path(
    dirname(__FILE__) . '/library'
    . PATH_SEPARATOR . get_include_path()
);

require_once 'Zend/Loader.php';

Zend_Loader::registerAutoload();

现在您可以简单地按照手册操作( http://framework.zend.com/manual/en/zend。 gdata.spreadsheets.html)。您可能感兴趣的主题是用于创建服务实例的“获取电子表格列表”和用于获取特定电子表格的所有工作表的“获取工作表列表”。

更新:

看起来 Zend_Gdata 包没有正确打包。我会注意到这一点以修复包裹。同时,我建议您下载完整的 Zend Framework 包。要正确使用 1.8 中的自动加载器,请执行以下操作:

require_once 'Zend/Loader/Autoloader.php';

Zend_Loader_Autoloader::getInstance();

A query to the following URL should list you all worksheets of a specific spreadsheet:

http://spreadsheets.google.com/feeds/worksheets/**spreadsheetKey**/private/full

To install and use Zend_Gdata, do the following:

Download the last package (http://framework.zend.com/releases/ZendGdata-1.10.7/ZendGdata-1.10.7.tar.gz) from the Zend Framework website. Now let's assume the following directors structure:

  • /index.php (your main file)
  • /library/Zend (extract the library/Zend folder in here)

Now in your index.php, do the following:

set_include_path(
    dirname(__FILE__) . '/library'
    . PATH_SEPARATOR . get_include_path()
);

require_once 'Zend/Loader.php';

Zend_Loader::registerAutoload();

Now you can simply follow the manual (http://framework.zend.com/manual/en/zend.gdata.spreadsheets.html). Interesting for you may be the topics "Get a List of Spreadsheets" for creating the service instance and "Get a List of Worksheets" to fetch all worksheets of a specific spreadsheet.

Update:

It looks like the Zend_Gdata package is not properly packaged. I will note that to get the package fixed. In the meantime, I suggest you to download the complete Zend Framework package. To use the autoloader in 1.8 correctly, do the following instead:

require_once 'Zend/Loader/Autoloader.php';

Zend_Loader_Autoloader::getInstance();
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文