我正试图通过Zend_u Gdata库更新谷歌电子表格。我确信用户id和密码是正确的。我认为问题出在电子表格键或工作表ID上。甚至我都不知道如何得到这个工作表ID。请帮我一下。这是m工作表的确切url。
https://docs.google.com/spreadsheet/ccc?key=0AmW1-CVeX7oOdGRkYURWNXVMRi1DTW9NTGNhZ09OTGc&hl=en_US#gid=0
这是我的密码。

$user = 'xxxxxxxxxxxxxxxxxxxxxx';
$pass = 'xxxxxxxxxxxxxxxxxx';
$service = Zend_Gdata_Spreadsheets::AUTH_SERVICE_NAME;
$client = Zend_Gdata_ClientLogin::getHttpClient($user, $pass, $service);
$spreadsheetService = new Zend_Gdata_Spreadsheets($client);
$spreadsheetKey = "0AmW1-CVeX7oOdGRkYURWNXVMRi1DTW9NTGNhZ09OTGc";
$worksheetId = "Sheet1";
try
{
    $spreadsheetService->insertRow(array('Prasad','10000'),$spreadsheetKey,$worksheetId);

}
catch(Exception $error)
{

    echo $error->getMessage() ;

}

这是我在浏览器屏幕上看到的错误信息。
应为响应代码200,得到400个无效的grid-id查询参数值。

最佳答案

我解决了这个问题。我可以通过下面的代码找到电子表格和工作表。

$user = 'xxxxxxxxxxxxxxx';
$pass = 'xxxxxxxxxxxxx';
$service            = Zend_Gdata_Spreadsheets::AUTH_SERVICE_NAME;
$client             = Zend_Gdata_ClientLogin::getHttpClient($user, $pass, $service);
$spreadsheetService = new Zend_Gdata_Spreadsheets($client);
$feed               = $spreadsheetService->getSpreadsheetFeed();
$sheetName = "Test1";
foreach($feed->entries as $entry)
{
    if($entry->title->text == $sheetName)
    {
        $spreadsheetURL = $entry->id;
        break;
    }
}

$spreadsheetKey = basename($spreadsheetURL);

$query = new Zend_Gdata_Spreadsheets_DocumentQuery();
$query->setSpreadsheetKey($spreadsheetKey);
$feed = $spreadsheetService->getWorksheetFeed($query);

echo "Spreadskeet Key : $spreadsheetKey <br/>";

foreach($feed->entries as $entry)
{
    echo "ID of sheet {$entry->title->text} is " . basename($entry->id) . " <br/>";
}

一旦我得到了这些值,我的脚本也就不起作用了。然后我发现,当我们定义数组时,应该在小写字母中不带空格地提到“key”。
$spreadsheetService->insertRow(array('name'=>'Prasad','value'=>'10000'),$spreadsheetKey,$worksheetId);

09-25 18:19