由于标准定义错误,因此无法通过PHP / google-sheets-API过滤Google表格(“无法绑定列表以映射字段'criteria'”)

问题描述 投票:0回答:1

我正在尝试使用Google-API-PHP-Client从我的网站将basic filter应用于Google Sheet。我只想显示A列中的值等于“ global_city_actors”的行。

不幸的是,我似乎无法正确构建请求。错误的根源似乎在“条件”规范中,尤其是列索引的“ 0”键(无论是否使用“”均不起作用)。我收到以下错误消息,但无法理解:

'requests [0] .set_basic_filter.filter'(地图)处的值无效,不能绑定列表以映射字段'criteria'。“,” errors“:[{” message“:““ requests [0] .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>');
}
php google-sheets filter google-sheets-api google-api-php-client
1个回答
0
投票

我还能够重现该错误,该错误仅在尝试为第一列创建过滤器时才受影响。此错误已在Google的问题跟踪器中报告:http://issuetracker.google.com/issues/144692636

© www.soinside.com 2019 - 2024. All rights reserved.