Filters: list

ต้องมีการให้สิทธิ์

แสดงตัวกรองทั้งหมดสำหรับบัญชี ลองใช้เลยหรือดูตัวอย่าง

ส่งคำขอ

คำขอ HTTP

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

พารามิเตอร์

ชื่อพารามิเตอร์ ค่า คำอธิบาย
พารามิเตอร์เส้นทาง
accountId string รหัสบัญชีที่ต้องการดึงข้อมูลตัวกรอง
พารามิเตอร์การค้นหาที่ไม่บังคับ
max-results integer จำนวนตัวกรองสูงสุดที่จะรวมไว้ในคำตอบนี้
start-index integer ดัชนีของเอนทิตีแรกที่จะดึงข้อมูล ใช้พารามิเตอร์นี้เป็นกลไกการใส่เลขหน้าร่วมกับพารามิเตอร์ max-results

การให้สิทธิ์

คำขอนี้ต้องได้รับการให้สิทธิ์อย่างน้อย 1 ขอบเขตต่อไปนี้ (อ่านเพิ่มเติมเกี่ยวกับการตรวจสอบสิทธิ์และการให้สิทธิ์)

ขอบเขต
https://www.googleapis.com/auth/analytics.edit
https://www.googleapis.com/auth/analytics.readonly

เนื้อหาของคำขอ

อย่าแสดงเนื้อหาของคำขอด้วยวิธีนี้

คำตอบ

หากทำสำเร็จ เมธอดนี้จะแสดงเนื้อหาการตอบสนองที่มีโครงสร้างต่อไปนี้

{
  "kind": "analytics#filters",
  "username": string,
  "totalResults": integer,
  "startIndex": integer,
  "itemsPerPage": integer,
  "previousLink": string,
  "nextLink": string,
  "items": [
    management.filters Resource
  ]
}
ชื่อพร็อพเพอร์ตี้ ค่า คำอธิบาย Notes
kind string ประเภทคอลเล็กชัน
username string รหัสอีเมลของผู้ใช้ที่ตรวจสอบสิทธิ์แล้ว
totalResults integer จำนวนผลลัพธ์ทั้งหมดสำหรับข้อความค้นหา โดยไม่คำนึงถึงจำนวนผลลัพธ์ในการตอบกลับ
startIndex integer ดัชนีเริ่มต้นของทรัพยากร ซึ่งเท่ากับ 1 โดยค่าเริ่มต้น หรือระบุโดยพารามิเตอร์การค้นหา Start-index
itemsPerPage integer จำนวนทรัพยากรสูงสุดที่การตอบกลับมีได้ โดยไม่คำนึงถึงจำนวนทรัพยากรที่แสดงผลจริง ค่าอยู่ในช่วง 1 ถึง 1,000 โดยมีค่า 1, 000 โดยค่าเริ่มต้น หรือระบุโดยพารามิเตอร์การค้นหาผลลัพธ์สูงสุด
items[] list รายการตัวกรอง

ตัวอย่าง

หมายเหตุ: ตัวอย่างโค้ดที่มีสำหรับวิธีการนี้ไม่ได้แสดงถึงภาษาโปรแกรมที่รองรับทั้งหมด (ดูรายการภาษาที่รองรับได้ในหน้าไลบรารีของไคลเอ็นต์)

Java

ใช้ไลบรารีของไคลเอ็นต์ Java

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

/*
 * Example #1:
 * Requests a list of all filters for the authorized user.
 */
try {
  Filters filters = analytics.management().filters().list("123456").execute();
} catch (GoogleJsonResponseException e) {
  System.err.println("There was a service error: "
      + e.getDetails().getCode() + " : "
      + e.getDetails().getMessage());
}

/*
 * Example 2:
 * The results of the list method are stored in the filters object.
 * The following code shows how to iterate through them.
 */
for (Filter filter : filters.getItems()) {
  System.out.println("Account Id = " + filter.getAccountId());
  System.out.println("Filter kind = " + filter.getKind());
  System.out.println("Filter Id = " + filter.getId());
  System.out.println("Filter Name = " + filter.getName());
  System.out.println("Filter Created = " + filter.getCreated());
  System.out.println("Filter Updated = " + filter.getUpdated());

  // Get the filter type.
  String filterType = filter.getType();
  System.out.println("filter type = " + filterType);

  // Print the properties if it is an "EXCLUDE" type filter.
  if (filterType == "EXCLUDE") {
    AnalyticsManagementFiltersFilterExpression details =
        filter.getExcludeDetails();
    System.out.println("Exclude field = " + details.getField());
    System.out.println("Exclude match type = " + details.getMatchType());
    System.out.println("Exclude case sensitive = "
        + details.getCaseSensitive());
    System.out.println("Exclude expression value = "
        + details.getExpressionValue());

  // Print the properties if it is an "INCLUDE" type filter.
  } else if (filterType == "INCLUDE") {
    AnalyticsManagementFiltersFilterExpression details =
        filter.getIncludeDetails();
    System.out.println("Include field = " + details.getField());
    System.out.println("Include match type = " + details.getMatchType());
    System.out.println("Include case sensitive = "
        + details.getCaseSensitive());
    System.out.println("Include expression value = "
        + details.getExpressionValue());

  // Print the properties if it is a "LOWERCASE" type filter.
  } else if (filterType == "LOWERCASE") {
    LowercaseDetails details = filter.getLowercaseDetails();
    System.out.println("Lower case field = " + details.getField());

  // Print the properties if it is an "UPPERCASE" type filter.
  } else if (filterType == "UPPERCASE") {
    UppercaseDetails details = filter.getUppercaseDetails();
    System.out.println("Upper case field = " + details.getField());


  // Print the details if it is a "SEARCH_AND_REPLACE" type filter.
  } else if (filterType == "SEARCH_AND_REPLACE") {
    SearchAndReplaceDetails details = filter.getSearchAndReplaceDetails();
    System.out.println("Search and replace field = " + details.getField());
    System.out.println("Search string = " + details.getSearchString());
    System.out.println("Replace string = " + details.getReplaceString());
    System.out.println("Search case sensitive = " + details.getCaseSensitive());

  // Print the details if it is an "ADVANCED" type filter.
  } else if (filterType == "ADVANCED") {
    AdvancedDetails details = filter.getAdvancedDetails();
    System.out.println("Advanced field A = " + details.getFieldA());
    System.out.println("Advanced extract A = " + details.getExtractA());
    System.out.println("Advanced field B = " + details.getFieldB());
    System.out.println("Advanced extract B = " + details.getExtractB());
    System.out.println("Advanced output field = " + details.getOutputToField());
    System.out.println("Advanced output constructor = "
        + details.getOutputConstructor());
    System.out.println("Advanced field A required = "
        + details.getFieldARequired());
    System.out.println("Advanced field B required = "
        + details.getFieldBRequired());
    System.out.println("Advanced override output field = "
        + details.getOverrideOutputField());
    System.out.println("Advanced case sensitive = "
        + details.getCaseSensitive());
  }
}

PHP

ใช้ไลบรารีของไคลเอ็นต์ PHP

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

/**
 * Example #1:
 * Requests a list of all filters for the authorized user.
 */
try {
  $filters = $analytics->management_filters
      ->listManagementFilters('123456');

} 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();
}


/**
 * Example #2:
 * The results of the list method are stored in the filters object.
 * The following code shows how to iterate through them.
 */
foreach ($filters->getItems() as $filter) {

  $html = <<<HTML
<pre>
Account id     = {$filter->getAccountId()}
Filter id      = {$filter->getId()}
Filter name    = {$filter->getName()}
Filter kind    = {$filter->getKind()}
Filter Created = {$filter->getCreated()}
Filter Updated = {$filter->getUpdated()}

HTML;

  // Get the filter type.
  $filterType = $filter->getType();
  $html .= <<<HTML
Filter Type = {$filterType}

HTML;

  // Print the properties if it is an "EXCLUDE" type filter.
  if ($filterType == 'EXCLUDE') {
    $details = $filter->getExcludeDetails();
    $html .= <<<HTML
Exclude field            = {$details->getField()}
Exclude match type       = {$details->getMatchType()}
Exclude case sensitive   = {$details->getCaseSensitive()}
Exclude expression value = {$details->getExpressionValue()}

HTML;

  // Print the properties if it is an "INCLUDE" type filter.
  } elseif ($filterType == 'INCLUDE') {
    $details = $filter->getIncludeDetails();
    $html .= <<<HTML
Include field = {$details->getField()}
Include match type       = {$details->getMatchType()}
Include case sensitive   = {$details->getCaseSensitive()}
Include expression value = {$details->getExpressionValue()}

HTML;

  // Print the properties if it is a "LOWERCASE" type filter.
  } elseif ($filterType == 'LOWERCASE') {
    $details = $filter->getLowercaseDetails();
    $html .= <<<HTML
Lower case field = {$details->getField()}

HTML;

  // Print the properties if it is an "UPPERCASE" type filter.
  } elseif ($filterType == 'UPPERCASE') {
    $details = $filter->getUppercaseDetails();
    $html .= <<<HTML
Upper case field = {$details->getField()}

HTML;

  // Print the details if it is a "SEARCH_AND_REPLACE" type filter.
  } elseif ($filterType == 'SEARCH_AND_REPLACE') {
    $details = $filter->getSearchAndReplaceDetails();
    $html .= <<<HTML
Search and replace field = {$details->getField()}
Search string            = {$details->getSearchString()}
Replace string           = {$details->getReplaceString()}
Search case sensitive    = {$details->getCaseSensitive()}

HTML;

  // Print the details if it is an "ADVANCED" type filter.
  } elseif ($filterType == 'ADVANCED') {
    $details = $filter->getAdvancedDetails();
    $html .= <<<HTML
Advanced field A               = {$details->getFieldA()}
Advanced extract A             = {$details->getExtractA()}
Advanced field B               = {$details->getFieldB()}
Advanced extract B             = {$details->getExtractB()}
Advanced output field          = {$details->getOutputToField()}
Advanced output constructor    = {$details->getOutputConstructor()}
Advanced field A required      = {$details->getFieldARequired()}
Advanced field B required      = {$details->getFieldBRequired()}
Advanced override output field = {$details->getOverrideOutputField()}
Advanced case sensitive        = {$details->getCaseSensitive()}

HTML;
  }

  $HTML .= '</pre>';
  print $html;
}

Python

ใช้ไลบรารีของไคลเอ็นต์ Python

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

# Example #1:
# Requests a list of all filters for the authorized user.
try:
  filters = analytics.management().filters().list(
      accountId='123456'
  ).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))


# Example #2:
# The results of the list method are stored in the filters object.
# The following code shows how to iterate through them.
for filter in filters.get('items', []):
  print 'Account Id = %s' % filter.get('accountId')
  print 'Filter Id = %s' % filter.get('id')
  print 'Filter Kind = %s' % filter.get('kind')
  print 'Filter Name = %s' % filter.get('name')
  print 'Filter Created = %s' % filter.get('created')
  print 'Filter Updated = %s' % filter.get('updated')

  # Get the filter type.
  filterType = filter.get('type')
  print 'Filter Type = %s' % filterType

  # Print the properties if the filter is of type "EXCLUDE".
  if filterType == 'EXCLUDE':
    details = filter.get('excludeDetails', {})
    print 'Exclude field = %s' % detail.get('field')
    print 'Exclude match type = %s' % details.get('matchType')
    print 'Exclude expression value = %s' % details.get('expressionValue')
    print 'Exclude case sensitive = %s' % details.get('caseSensitive')

  # Print the properties if the filter is of type 'INCLUDE'.
  if filterType == 'INCLUDE':
    details = filter.get('includeDetails', {})
    print 'Include field = %s' % details.get('field')
    print 'Include match type = %s' % details.get('matchType')
    print 'Include expression value = %s' % details.get('expressionValue')
    print 'Include case sensitive = %s' % details.get('caseSensitive')

  # Print the properties if the filter is of type 'LOWERCASE'.
  if filterType == 'LOWERCASE':
    details = filter.get('lowercaseDetails', {})
    print 'Lowercase field = %s' % details.get('field')

  # Print the properties if the filter is of type 'UPPERCASE'.
  if filterType == 'UPPERCASE':
    details = filter.get('uppercaseDetails', {})
    print 'Uppercase field = %s' % details.get('field')

  # Print the properties if the filter is of type 'SEARCH_AND_REPLACE'.
  if filterType == 'SEARCH_AND_REPLACE':
    details = filter.get('searchAndReplaceDetails', {})
    print 'Search and replace field = %s' % details.get('field')
    print 'Search string = %s' % details.get('searchString')
    print 'Replace string = %s' % details.get('replaceString')
    print 'Search and replace case sensitive = %s' % details.get('caseSensitive')

  # Print the properties if the filter is of type 'ADVANCED'.
  if filterType == 'ADVANCED':
    details = filter.get('advancedDetails', {})
    print 'Advanced field A = %s' % details.get('fieldA')
    print 'Advanced extract A = %s' % details.get('extractA')
    print 'Advanced field B = %s' % details.get('fieldB')
    print 'Advanced extract B = %s' % details.get('extractB')
    print 'Advanced output field = %s' % details.get('outputToField')
    print 'Advanced output constructor = %s' % details.get('outputConstructor')
    print 'Advanced field A required = %s' % details.get('fieldARequired')
    print 'Advanced field B required = %s' % details.get('fieldBRequired')
    print 'Advanced override output field = %s' % details.get('overrideOutputField')
    print 'Advanced case sensitive = %s' % details.get('caseSensitive')



JavaScript

ใช้ไลบรารีของไคลเอ็นต์ JavaScript

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

/*
 * Example 1:
 * Requests a list of all filters for the authorized user.
 */
function listFilters() {
  var request = gapi.client.analytics.management.filters.list({
    'accountId': '123456'
  });
  request.execute(printFilters);
}

/*
 * Example 2:
 * The results of the list method are passed as the results object.
 * The following code shows how to iterate through them.
 */
function printFilters(results) {
  if (results && !results.error) {
    var filters = results.items;
    for (var i = 0, filter; filter = filters[i]; i++) {
      console.log('Account Id: ' + filter.accountId);
      console.log('Filter Id: ' + filter.id);
      console.log('Filter Kind: ' + filter.kind);
      console.log('Filter Name: ' + filter.name);
      console.log('Filter Created: ' + filter.created);
      console.log('Filter Updated: ' + filter.updated);

      // Get the filter type.
      var filterType = filter.type;
      console.log('Filter Type: ' + filter.type);

      // Print the properties if the filter is of type 'Exclude'.
      if (filterType == 'EXCLUDE') {
        var details = filter.excludeDetails;
        console.log('Exclude field: ' + details.field);
        console.log('Exclude match type: ' + details.matchType);
        console.log('Exclude expression value: ' + details.expressionValue);
        console.log('Exclude case sensitive: ' + details.caseSensitive);
      }

      // Print the properties if the filter is of type 'INCLUDE'.
      if (filterType == 'INCLUDE') {
        var details = filter.includeDetails;
        console.log('Include field: ' + details.field);
        console.log('Include match type: ' + details.matchType);
        console.log('Include expression value: ' + details.expressionValue);
        console.log('Include case sensitive: ' + details.caseSensitive);
      }

      // Print the properties if the filter is of type 'LOWERCASE'.
      if (filterType == 'LOWERCASE') {
        var details = filter.lowercaseDetails;
        console.log('Lowercase field: ' + details.field);
      }

      // Print the properties if the filter is of type 'UPPERCASE'.
      if (filterType == 'UPPERCASE') {
        var details = filter.lowercaseDetails;
        console.log('Uppercase field: ' + details.field);
      }

      // Print the properties if the filter is of type 'SEARCH_AND_REPLACE'.
      if (filterType == 'SEARCH_AND_REPLACE') {
        var details = filter.searchAndReplaceDetails;
        console.log('Search and replace field: ' + details.field);
        console.log('Search string: ' + details.searchString);
        console.log('Replace string: ' + details.replaceString);
        console.log('Search case sensitive: ' + details.caseSensitive);
      }

      // Print the properties if the filter is of type 'ADVANCED'.
      if (filterType == 'ADVANCED') {
        var details = filter.advancedDetails;
        console.log('Advanced field A: ' + details.fieldA);
        console.log('Advanced extract A: ' + details.extractA);
        console.log('Advanced field B: ' + details.fieldB);
        console.log('Advanced extract B: ' + details.extractB);
        console.log('Advanced output field: ' + details.outputToField);
        console.log('Advanced output constructor: '
            + details.outputConstructor);
        console.log('Advanced field A required: ' + details.fieldARequired);
        console.log('Advanced field B required: ' + details.fieldBRequired);
        console.log('Advanced override output field: '
            + details.overrideOutputField);
        console.log('Advanced case sensitive: ' + details.caseSensitive);
      }
    }
  }
}

ลองใช้เลย

ใช้ API Explorer ด้านล่างเพื่อเรียกใช้เมธอดนี้ในข้อมูลสดและดูการตอบสนอง หรือลองใช้เครื่องมือสำรวจแบบสแตนด์อโลน