dsubq24666 2012-02-06 09:15
浏览 57
已采纳

Zend_GData Spreadsheet - grid-id的查询参数值无效

I am trying to update a google spreadsheet through Zend_GData library. I am sure the user ID and password is correct. I think the issue is with spreadsheet key or worksheet ID. Even I don't know exactly how to get this worksheetID. Kindly help me on this. This is the exact URL to m worksheet.

https://docs.google.com/spreadsheet/ccc?key=0AmW1-CVeX7oOdGRkYURWNXVMRi1DTW9NTGNhZ09OTGc&hl=en_US#gid=0

Here is my code.

$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() ;

}

And this is the error message I see on my browser screen.

Expected response code 200, got 400 Invalid query parameter value for grid-id.

  • 写回答

2条回答 默认 最新

  • douyun6399 2012-02-06 10:40
    关注

    I fixed the issue. I could find the SpreadsheetKey and WorkSheetID by using bellow code.

    $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/>";
    }
    

    Once I got those values also my script didn't work. Then I found that when we define the array the 'Key's should mentioned in lower case with no spaces.

    $spreadsheetService->insertRow(array('name'=>'Prasad','value'=>'10000'),$spreadsheetKey,$worksheetId);
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 请问一下这个运行结果是怎么来的
  • ¥15 这个复选框什么作用?
  • ¥15 单通道放大电路的工作原理
  • ¥30 YOLO检测微调结果p为1
  • ¥20 求快手直播间榜单匿名采集ID用户名简单能学会的
  • ¥15 DS18B20内部ADC模数转换器
  • ¥15 做个有关计算的小程序
  • ¥15 MPI读取tif文件无法正常给各进程分配路径
  • ¥15 如何用MATLAB实现以下三个公式(有相互嵌套)
  • ¥30 关于#算法#的问题:运用EViews第九版本进行一系列计量经济学的时间数列数据回归分析预测问题 求各位帮我解答一下