我正在尝试使用从我的网站将一个基本滤波器应用到谷歌单张。我只想显示A列中的值等于"global_city_actors“的行。
不幸的是,我似乎无法正确地构造请求。错误的来源似乎在“标准”规范中,特别是列索引的"0“键(不管是否使用"”)。我收到以下错误消息,但无法理解:
无效值在'requests.set_basic_filter.filter‘(地图),不能绑定一个列表来映射字段’标准‘。“错误”:[{“消息”:“无效值在'requests.set_basic_filter.filter’(地图),不能绑定列表以映射字段‘标准’。”,“原因”:“无效”},“状态”:"INVALID_ARGUMENT“}
如果有任何线索我会很感激的。这是我的代码:
// The first bit is inspired by: https://www.fillup.io/post/read-and-write-google-sheets-from-php/
require_once(APPPATH.'third_party/google-api-php-client-2.2.3/vendor/autoload.php');
$this->client = new Google_Client();
$this->client->setApplicationName('My Test API');
$this->client->setScopes([Google_Service_Sheets::SPREADSHEETS]);
$this->client->setAccessType('offline');
$this->client->setAuthConfig(APPPATH.'third_party/google-api-php-client-2.2.3/credentials/.....json');
$this->service = new Google_Service_Sheets($this->client);
$this->spreadsheetId = '1yRg6Kai6MwKcE8ZKdCggfWwPZVIOu-MfByvgWLSEiUI';
// This is the faulty request:
$requests = [
new Google_Service_Sheets_Request([
'setBasicFilter' => [
'filter' => [
'range' => [
'sheetId' => 0,
'startColumnIndex' => 0,
'endColumnIndex' => 0
],
'criteria' => [
"0" => [
'condition' => [
'type' => 'TEXT_EQ',
'values' => [
'userEnteredValue' => 'global_city_actors'
]
]
]
]
]
]
])
];
$batchUpdateRequest = new Google_Service_Sheets_BatchUpdateSpreadsheetRequest([
'requests' => $requests
]);
try {
$response_object = $this->service->spreadsheets->batchUpdate($this->spreadsheetId, $batchUpdateRequest);
}
catch (Exception $e) {
return show_error('An error occurred: <strong>'.$e->getMessage().'</strong></p>');
}
发布于 2019-11-18 08:55:48
我还能够重现错误,这仅在试图为第一列创建过滤器时才会影响。这个错误已经在Google的问题跟踪器:http://issuetracker.google.com/issues/144692636中报告了。
发布于 2020-01-07 17:53:16
我刚刚遇到了这个问题,我想我要提到的是使用stdClass在github问题上列出的一个解决方法- https://github.com/googleapis/google-api-php-client/issues/1748#issuecomment-560550645。
$criteria = new stdClass;
$criteria->{'0'} = array(
'condition' => array(
'type' => 'TEXT_EQ',
'values' => array(
'userEnteredValue' => 'global_city_actors'
)
)
);
$body = new Google_Service_Sheets_BatchUpdateSpreadsheetRequest(
array(
'requests' => array(
'setBasicFilter' => array(
'filter' => array(
'range' => [
'sheetId' => 0,
'startColumnIndex' => 0,
'endColumnIndex' => 0
],
'criteria' => $criteria
)
)
)
)
);
var_dump($service->spreadsheets->batchUpdate($spreadsheetId, $body));
解决办法对我来说很管用。希望这能有所帮助。
https://stackoverflow.com/questions/58886429
复制