过滤器:patch

使用集合让一切井井有条 根据您的偏好保存内容并对其进行分类。

需要授权

更新现有过滤器。此方法支持修补语义。 立即试用查看示例

请求

HTTP 请求

PATCH https://www.googleapis.com/analytics/v3/management/accounts/accountId/filters/filterId

参数

参数名称 说明
路径参数
accountId string 过滤器所属的帐户 ID。
filterId string 要更新的过滤器的 ID。

授权

此请求需要获得下列范围的授权(详细了解身份验证和授权)。

范围
https://www.googleapis.com/auth/analytics.edit

请求正文

在请求正文中,根据修补语义的规则提供 management.filter 资源的相关部分。the rules of patch semantics.

响应

如果成功,此方法将在响应正文中返回一个 management.filter 资源

示例

备注:此方法的代码示例并未列出所有受支持的编程语言(请参阅客户端库页面,查看受支持的语言列表)。

Java

使用 Java 客户端库

/*
 * Note: This code assumes you have an authorized Analytics service object.
 * See the Filters Developer Guide for details.
 */

/*
 * This example patches an existing filter.
 */

// Construct the filter Expression object.
AnalyticsManagementFiltersFilterExpression details = new
    AnalyticsManagementFiltersFilterExpression();
details.setField("GEO_DOMAIN");
details.setMatchType("EQUAL");
details.setExpressionValue("example.com");
details.setCaseSensitive(false);

// Construct the body of the request.
Filter body = new Filter();
body.setName("My Domain Filter");
body.setType("EXCLUDE");
body.setExcludeDetails(details);

try {
  analytics.management().filters().patch("123456", "1223334444", body).execute();
} catch (GoogleJsonResponseException e) {
  System.err.println("There was a service error: "
      + e.getDetails().getCode() + " : "
      + e.getDetails().getMessage());
}

PHP

使用 PHP 客户端库

/**
 * Note: This code assumes you have an authorized Analytics service object.
 * See the Filters Developer Guide for details.
 */

/**
 * This request patches an existing filter.
 */
try {

  // Construct the filter expression object.
  $details = new Google_Service_Analytics_FilterExpression();
  $details->setField("GEO_DOMAIN");
  $details->setMatchType("EQUAL");
  $details->setExpressionValue("example.com");
  $details->setCaseSensitive(false);

  // Construct the filter and set the details.
  $filter = new Google_Service_Analytics_Filter();
  $filter->setName("My Domain Filter");
  $filter->setType("EXCLUDE");
  $filter->setExcludeDetails($details);
  $analytics->management_filters->patch('123456', '7654321', $filter);
} catch (apiServiceException $e) {
  print 'There was an Analytics API service error '
      . $e->getCode() . ':' . $e->getMessage();
} catch (apiException $e) {
  print 'There was a general API error '
      . $e->getCode() . ':' . $e->getMessage();
}

Python

使用 Python 客户端库

# Note: This code assumes you have an authorized Analytics service object.
# See the Filters Developer Guide for details.

# This request patches an existing filter.
try:
  analytics.management().filters().patch(
      accountId='123456',
      filterId='1223334444',
      body={
          'name': 'My Domain Filter',
          'type': 'EXCLUDE',
          'excludeDetails': {
              'field': 'GEO_DOMAIN',
              'matchType': 'EQUAL',
              'expressionValue': 'example.com',
              'caseSensitive': False
              }
      }
  ).execute()

except TypeError, error:
  # Handle errors in constructing a query.
  print 'There was an error in constructing your query : %s' % error

except HttpError, error:
  # Handle API errors.
  print ('There was an API error : %s : %s' %
         (error.resp.status, error.resp.reason))

JavaScript

使用 JavaScript 客户端库

/*
 * Note: This code assumes you have an authorized Analytics client object.
 * See the Filters Developer Guide for details.
 */

/*
 * This request patches an existing filter.
 */
function patchFilter() {
  var request = gapi.client.analytics.management.filters.patch(
    {
      'accountId': '123456',
      'filterId': '1223334444',
      'resource': {
        'name': 'My Domain Filter',
        'type': 'EXCLUDE',
        'excludeDetails': {
          'field': 'GEO_DOMAIN',
          'matchType': 'EQUAL',
          'expressionValue': 'example.com',
          'caseSensitive': false
        }
      }
    });
  request.execute(function (response) { // Handle the response. });
}

试试看!

请使用下面的 API Explorer 针对实时数据调用此方法并查看响应。或者,您还可以尝试使用独立的 Explorer