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

时间:2010-08-21 19:24:44

标签: php curl google-docs google-visualization google-sheets

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

<?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的建议给我这个错误 - &gt;

  

注意:   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 /装载机/ Autoloader.php)   [function.require-once]:失败了   open stream:没有这样的文件或目录   在   /home/c3webdev/public_html/library/Zend/Loader.php   在第267行

     

致命错误:require_once()   [function.require]:打开失败   需要'Zend / Loader / Autoloader.php'   (include_path中= '/家庭/ c3webdev /的public_html /库:。:/ usr / lib中/ PHP:在/ usr / local / lib目录/ PHP的')   在   /home/c3webdev/public_html/library/Zend/Loader.php   在第267行

3 个答案:

答案 0 :(得分:2)

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

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

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

从Zend Framework网站下载最后一个包(http://framework.zend.com/releases/ZendGdata-1.10.7/ZendGdata-1.10.7.tar.gz)。现在让我们假设以下董事结构:

  • /index.php(您的主文件)
  • / library / Zend(在这里解压缩库/ 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();

答案 1 :(得分:0)

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

如上所述,这是您可以使用电子表格的方式

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

然后从那里你可以获得特定电子表格的网址,然后从那里你可以从那里获取数据

List返回具有适当标题的数据

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

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

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

以下是google spreadsheets api参考

的更多信息

答案 2 :(得分:0)

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

您可以在网络上将您的Google电子表格发布为csv(使用私人网址),只需通过 fopen / fgetcsv 访问它:

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

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