【问题标题】:Google Sheet UpdateValuesResponse()谷歌表格 UpdateValuesResponse()
【发布时间】:2017-09-20 12:37:02
【问题描述】:

我在 Google Sheet 中更新值修改了这个 quiqstartfile:https://developers.google.com/sheets/api/quickstart/php 更新后,我需要来自谷歌 api 的响应,一切正常(它没有错误)。如何测试更新成功?怎么做? 我试过了:

$result = $service->spreadsheets_values->update($spreadsheetId, $range, $body, $params);
$test=$result->UpdateValuesResponse();
printf($test);

并且有错误:

PHP 致命错误:未捕获的错误:调用未定义的方法 Google_Service_Sheets_UpdateValuesResponse::UpdateValuesResponse() /var/www/html/writegs.php:101 堆栈跟踪: > #0 {main} 在 /var/www/html/writegs.php 第 101 行抛出

【问题讨论】:

    标签: php google-sheets-api


    【解决方案1】:

    在此处查看文档: https://developers.google.com/sheets/api/reference/rest/v4/spreadsheets.values/update

    根据那里给出的 PHP 示例,您从 update 返回的响应是一个 UpdateValuesResponse 对象。这不是一种方法。

    因此,如果您只是想测试您是否获得了成功的响应,请尝试:

    $result = $service->spreadsheets_values->update($spreadsheetId, $range, $body, $params);
    echo '<pre>', var_export($result , true), '</pre>', "\n";
    
    $result = json_decode($result);
    
    $updatedCells = $result->updatedCells;
    

    【讨论】:

    • 这是工作。谢谢。您能帮我将“updatedCells”值转换为变量进行检查吗?
    • @Alex88 我已经更新了我的答案,您应该可以使用json_decode 将 Google 的 JSON 响应转换为对象。
    • 谢谢。但我有它:code 103 $result = json_decode($result); PHP Warning: json_decode() expects parameter 1 to be string, object given in /var/www/html/writegs.php on line 103 105 $updatedCells = $result-&gt;updatedCells; PHP Notice: Trying to get property of non-object in /var/www/html/writegs.php on line 105
    • 您的代码:$result = $service->spreadsheets_values->update($spreadsheetId, $range, $body, $params); echo '
      ', var_export($result, true), '
      ', "\n"; $result = json_decode($result); $updatedCells = $result->updatedCells;
    • 我有答案:“PHP 警告:json_decode() 期望参数 1 为字符串,对象在 /v ar/www/html/writegs.php 第 103 行 PHP 注意:尝试获取属性/var/www/html/writegs.php 第 105 行中的非对象"你能帮忙解决吗?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-12-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多