gpt4 book ai didi

php - 使用 Zend Gdata 在 Google 电子表格中插入行时出错

转载 作者:塔克拉玛干 更新时间:2023-11-03 06:03:48 24 4
gpt4 key购买 nike

我正在尝试使用 Zend Gdata 1.11 库在 Google 电子表格中插入行的最简单方案。电子表格的单元格 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//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>

它迭代电子表格并写入名称和 ID,这意味着我已登录并可以访问,但在插入行时出现错误:“很抱歉,发生服务器错误。请稍候并尝试正在重新加载您的电子表格。”

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"

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

最佳答案

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

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

如果我有名为“My Column 2”的列,在数组中它应该是“mycolumn2”。

关于php - 使用 Zend Gdata 在 Google 电子表格中插入行时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7455239/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com