Error inserting row in Google Spreadsheet using Zend Gdata

青春壹個敷衍的年華 提交于 2019-12-07 10:40:34

问题


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...?


回答1:


$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'.




回答2:


I had a similar problem which has arisen due to the presence of spaces in the array. Remove spaces helped me:

$rowData = array('kolona' => 'smurf'); - your code
$rowData = array('kolona'=>'smurf'); - my code


来源:https://stackoverflow.com/questions/7455239/error-inserting-row-in-google-spreadsheet-using-zend-gdata

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!