【发布时间】:2021-06-25 21:17:19
【问题描述】:
我的第一篇文章,与下面的文章有关 How do I set a basic filter in php using google sheets api?
我在下面实现了代码,但收到此消息,我不确定是什么原因:
收到无效的 JSON 负载。 'requests[0]' 中的未知名称“requests”:找不到字段。
$criteria = new \stdClass();
$criteria->{'2'} = array(
'condition' => array(
'type' => 'NUMBER_EQ',
'values' => array(
'userEnteredValue' => '5'
)
)
);
$requests = [
new Google_Service_Sheets_Request( array(
'requests' => array(
'setBasicFilter' => array(
'filter' => array(
'range' => [
'sheetId' => 0,
'startRowIndex' => 4,
'endRowIndex' => 20,
'startColumnIndex' => 0,
'endColumnIndex' => 11
],
'criteria' => $criteria
),
),
'includeSpreadsheetInResponse' => true,
'responseIncludeGridData' => true
)
)
)
];
$requestBody = new Google_Service_Sheets_BatchUpdateSpreadsheetRequest(array('requests' => $requests));
$response = $sheets->spreadsheets->batchUpdate($spreadsheetId, $requestBody);
【问题讨论】:
-
我不知道这个请求应该是什么样子,但是你有一个名为“requests”的数组,它被包裹在
Google_Service_Sheets_Request中,然后被包裹在 another 数组称为“请求”。可能想确认这是使用它的正确方法。 -
您是否尝试过使用 API 资源管理器测试您的请求参数?我刚刚注意到您的条件数组最初设置为 2
$criteria->{'2'}。如果您可以共享样本表,以便我们能够复制您的问题,是否有可能。 Share a test sheet
标签: php json google-sheets google-sheets-api