无法使用 Zend_Gdata 打开电子表格?
<?php
include('Zend/Gdata.php');
include('Zend/Gdata/Spreadsheets.php');
include('Zend/Gdata/ClientLogin.php');
$service = Zend_Gdata_Spreadsheets::AUTH_SERVICE_NAME;
$client = Zend_Gdata_ClientLogin::getHttpClient('[email protected]', 'password', $service);
$spreadsheetService = new Zend_Gdata_Spreadsheets($client);
$sheets = $spreadsheetService->getSpreadsheetFeed();
foreach ($sheets as $sheet) {
//echo get_class($sheet) . '<br>'; exit;
echo $sheet->getContent() . '<br>';
echo $sheet->getId() . '<br>';
$query = new Zend_Gdata_Spreadsheets_DocumentQuery();
$query->setSpreadsheetKey($sheet->getId());
$feed = $spreadsheetService->getWorksheetFeed($query);
echo '<pre>';
print_r($feed); exit;
}
这是我这样做时遇到的错误:
Fatal error: Uncaught exception 'Zend_Gdata_App_HttpException' with message 'Expected response code 200, got 400 Invalid request URI'
这对我来说没有多大意义。如果电子表格键无效,为什么 $sheet->getId() 会返回它?
<?php
include('Zend/Gdata.php');
include('Zend/Gdata/Spreadsheets.php');
include('Zend/Gdata/ClientLogin.php');
$service = Zend_Gdata_Spreadsheets::AUTH_SERVICE_NAME;
$client = Zend_Gdata_ClientLogin::getHttpClient('[email protected]', 'password', $service);
$spreadsheetService = new Zend_Gdata_Spreadsheets($client);
$sheets = $spreadsheetService->getSpreadsheetFeed();
foreach ($sheets as $sheet) {
//echo get_class($sheet) . '<br>'; exit;
echo $sheet->getContent() . '<br>';
echo $sheet->getId() . '<br>';
$query = new Zend_Gdata_Spreadsheets_DocumentQuery();
$query->setSpreadsheetKey($sheet->getId());
$feed = $spreadsheetService->getWorksheetFeed($query);
echo '<pre>';
print_r($feed); exit;
}
Here's the error I get when I do that:
Fatal error: Uncaught exception 'Zend_Gdata_App_HttpException' with message 'Expected response code 200, got 400 Invalid request URI'
That doesn't make a lot of sense to me. If they spreadsheet key was invalid why would $sheet->getId() be returning it?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
编辑:已更新此内容,使其更符合我认为您想要的内容 - 让我知道它是否不合时宜,但这可能会有所帮助。我假设您正在使用带有 Zend Framework 的 MVC 模式,因此您可能需要进行相应的调整,否则
尝试这个类:
然后在您选择的控制器中:
然后在您的视图中:
注意:虽然可能还有其他方法可以做到这一点,但您可以通过使用类似这样的东西来获取电子表格键(我刚刚修改了视图中的内容):
在上面的示例中,我试图说明如何仅使用该键。如果我自己在 ZF 中执行此操作,则在路由到我想要使用 getRows() 等方法的操作时,我会将 $spreadsheetKey 绑定为 url 中的参数。如果你想要一个例子,我可以把一个放在一起吗?
感谢我对您想要实现的目标进行了一些猜测,但希望这会有所帮助。
干杯,
戴夫
关于两步身份验证:一些稍微偏离主题但可能会有所帮助的事情是确保在 Google 帐户上关闭两步身份验证,因为它会阻止您通过这种方式进行连接。
EDIT: Have updated this to make it more in line with what I think you want - let me know if it's off the mark but this may help. I'm assuming you're using an MVC pattern with Zend Framework so you may need to tweak accordingly otherwise
Try this class:
Then this in your chosen controller:
Then this in your view:
NOTE: While there are probably other ways of doing this you could get hold of just the spreadsheet key by using something like this (I've just modified what would be in the view):
In the above example I was trying to illustrate how you might use just the key. If I was doing this in ZF myself I'd bind $spreadsheetKey as a parameter in the url when routing to an action where I'd want to use a method such as getRows(). If you want an example I could put one together?
Appreciate I'm guessing a bit as to what you want to achieve but hopefully this helps.
Cheers,
Dave
ABOUT 2 STEP AUTH: Something slightly off topic which may be helpful is to make sure 2-step authentication is turned off on the Google account as it will stop you from connecting this way.