使用Zend Gdata在Google Spreadsheet中插入行时出错 [英] Error inserting row in Google Spreadsheet using Zend Gdata

查看:177
本文介绍了使用Zend Gdata在Google Spreadsheet中插入行时出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用Zend Gdata 1.11库在Google Spreadsheet中插入行的最简单方案。电子表格在单元格A1中包含单词'Kolona'。
这里是整个php文件:

 <?php 
require_once'Zend / Loader.php' ;
Zend_Loader :: loadClass('Zend_Gdata');
Zend_loader :: loadClass('Zend_Gdata_Query');
Zend_Loader :: loadClass('Zend_Gdata_Spreadsheets');
Zend_Loader :: loadClass('Zend_Gdata_ClientLogin');
?>
<!DOCTYPE html PUBLIC - // W3C // DTD XHTML 1.0 Transitional // ENhttp://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">
< html xmlns =http://www.w3.org/1999/xhtml>
< head>
< meta http-equiv =Content-Typecontent =text / html; charset = utf-8/>
< title>无标题文档< / title>
< / head>

< body>
<?php
error_reporting(E_ALL);
ini_set(display_errors,1);

$ user =xxxx;
$ pass =xxxx;
$ service ='wise';

$客户= Zend_Gdata_ClientLogin :: getHttpClient($用户,$通,$服务,NULL,Zend_Gdata_ClientLogin :: DEFAULT_SOURCE,NULL,NULL,Zend_Gdata_ClientLogin :: CLIENTLOGIN_URI,GOOGLE);

$ spreadsheetService = new Zend_Gdata_Spreadsheets($ client);

$ feed = $ spreadsheetService-> getSpreadsheetFeed();

foreach($ feed as $ entry){
echo'Title:'。 $ entry->标题。 ' - ';
echo'Id:'。 $ entry-> id。 '< br />';
}
$ rowData = array('Kolona'=>'smurf');

$ spreadsheetKey ='xxxx';
$ worksheetId ='xxx';

try {
$ insertedListEntry = $ spreadsheetService-> insertRow($ rowData,
$ spreadsheetKey,
$ worksheetId);
}
catch(Zend_Gdata_App_HttpException $ exception){
echoError:。 $ exception-> GETRESPONSE() - > getRawBody();
}
?>
< / body>
< / html>

它迭代电子表格并写入名称和ID,这意味着我已登录并可以访问,但我们很抱歉,发生了一个服务器错误,请等待并尝试重新加载您的电子表格。

 完整的错误是:致命错误:未捕获异常'Zend_Gdata_App_HttpException'带有消息'预期响应代码200,得到400我们很抱歉,发生服务器错误。请稍候并尝试重新加载您的电子表格。 'in C:\wamp\www\ks\gdata\ZendGdata-1.1.10\library\Zend\Gdata\App.php:709 Stack trace:#0 C:\wamp\\ \\www\ks\gdata\ZendGdata-1.11.10\library\Zend\Gdata.php(219):Zend_Gdata_App-> performHttpRequest( 'POST',的 'https:// ...传播' ,Array,'< atom:entry xml ...','application / ato ...',NULL)#1 C:\wamp\\\\\\\\\\\\\\\\\\\\ \\lib rary_\\Zend\Gdata\App.php(900):Zend_Gdata-> performHttpRequest('POST','https:// spreads ...',Array,'< atom:entry xml ...' ,'application / ato ...')#2 C:\wamp\www\ks\gdata\ZendGdata-1.1.10\library\Zend\Gdata\App.php(975) :Zend_Gdata_App-> post('< atom:entry xml ...','https:// spreads ...',NULL,NULL,Array)#3 C:\wamp\www\ks\\ \\gdata\ZendGdata-1.11.10\library\Zend\Gdata\Spreadsheets.php(336):Zend_Gdata_App-> insertEntry( '<原子:条目的xml ...',https://开头spread ...','Zend_Gdata_Spre ...')#4 C:\wamp\www\ks\gdata\gs in C:\wamp\www\\\\\\\\\\\\\ -1.11.10 \ library \Zend\Gdata\App.php on line 709

我在做什么错了?我应该以特定的方式创建电子表格吗??

解决方案

  $ rowData = array('Kolona'=>'smurf'); - 错误
$ rowData = array('kolona'=&'; smurf'); - 正确的

显然,列名必须用小写字母表示,且不能有空格。我可以在Google电子表格中保留Kolona,只需在代码中使用小写字母。



如果我有名为My Column 2的列,应该是'mycolumn2'。


I'm trying the simplest possible scenario to insert row in Google Spreadsheet using Zend Gdata 1.11 library. Spreadsheet has word 'Kolona' in cell A1. Here is entire php file:

<?php
require_once 'Zend/Loader.php';
Zend_Loader::loadClass('Zend_Gdata');
Zend_loader::loadClass('Zend_Gdata_Query');
Zend_Loader::loadClass('Zend_Gdata_Spreadsheets');
Zend_Loader::loadClass('Zend_Gdata_ClientLogin');
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>

<body>
<?php
error_reporting(E_ALL);
ini_set("display_errors", 1);

$user = "xxxx";
$pass = "xxxx";
$service = 'wise';

$client = Zend_Gdata_ClientLogin::getHttpClient($user, $pass, $service, null, Zend_Gdata_ClientLogin::DEFAULT_SOURCE, null, null, Zend_Gdata_ClientLogin::CLIENTLOGIN_URI, 'GOOGLE');

$spreadsheetService = new Zend_Gdata_Spreadsheets($client);

$feed = $spreadsheetService->getSpreadsheetFeed();

foreach ($feed as $entry) {
echo 'Title: ' . $entry->title . ' - ';
echo 'Id: ' . $entry->id . '<br />';
}
$rowData = array('Kolona' => 'smurf');

$spreadsheetKey = 'xxxx';
$worksheetId = 'xxx';

try{
$insertedListEntry = $spreadsheetService->insertRow($rowData,
                                                    $spreadsheetKey,
                                                    $worksheetId);
}
catch(Zend_Gdata_App_HttpException $exception) {  
    echo "Error: " . $exception->getResponse()->getRawBody();  
} 
?>
</body>
</html>

It iterates spreadsheets and writes names and ids which means that I'm logged in and have access, but whet it comes to inserting row I get error: "We're sorry, a server error has occurred. Please wait and try reloading your spreadsheet."

Full error is: "Fatal error: Uncaught exception 'Zend_Gdata_App_HttpException' with message 'Expected response code 200, got 400 We&#39;re sorry, a server error has occurred. Please wait and try reloading your spreadsheet.' in C:\wamp\www\ks\gdata\ZendGdata-1.11.10\library\Zend\Gdata\App.php:709 Stack trace: #0 C:\wamp\www\ks\gdata\ZendGdata-1.11.10\library\Zend\Gdata.php(219): Zend_Gdata_App->performHttpRequest('POST', 'https://spreads...', Array, '<atom:entry xml...', 'application/ato...', NULL) #1 C:\wamp\www\ks\gdata\ZendGdata-1.11.10\library\Zend\Gdata\App.php(900): Zend_Gdata->performHttpRequest('POST', 'https://spreads...', Array, '<atom:entry xml...', 'application/ato...') #2 C:\wamp\www\ks\gdata\ZendGdata-1.11.10\library\Zend\Gdata\App.php(975): Zend_Gdata_App->post('<atom:entry xml...', 'https://spreads...', NULL, NULL, Array) #3 C:\wamp\www\ks\gdata\ZendGdata-1.11.10\library\Zend\Gdata\Spreadsheets.php(336): Zend_Gdata_App->insertEntry('<atom:entry xml...', 'https://spreads...', 'Zend_Gdata_Spre...') #4 C:\wamp\www\ks\gdata\gs in C:\wamp\www\ks\gdata\ZendGdata-1.11.10\library\Zend\Gdata\App.php on line 709"

What am I doing wrong? Should I create spreadsheet in a specific manner or something...?

解决方案

$rowData = array('Kolona' => 'smurf'); - wrong
$rowData = array('kolona' => 'smurf'); - correct

Obviously, column names must be stated in small letters and without spaces. I can keep "Kolona" in Google spreadsheet, just have to use lower-case letters in code.

If I had column named "My Column 2", in array it should be 'mycolumn2'.

这篇关于使用Zend Gdata在Google Spreadsheet中插入行时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆