Google Ads Links: list

Cần có uỷ quyền

Liệt kê các liên kết webProperty-Google Ads cho một thuộc tính web nhất định. Thử ngay hoặc xem ví dụ.

Yêu cầu

Yêu cầu HTTP

GET https://www.googleapis.com/analytics/v3/management/accounts/accountId/webproperties/webPropertyId/entityAdWordsLinks

Tham số

Tên thông số Giá trị Nội dung mô tả
Tham số đường dẫn
accountId string Mã của tài khoản chứa tài sản web đã cho.
webPropertyId string Mã tài sản web để truy xuất các đường liên kết Google Ads.
Tham số truy vấn không bắt buộc
max-results integer Số đường liên kết webProperty-Google Ads tối đa cần đưa vào phản hồi này.
start-index integer Chỉ mục của mối liên kết webProperty-Google Ads đầu tiên cần truy xuất. Sử dụng thông số này làm cơ chế phân trang cùng với thông số kết quả tối đa.

Ủy quyền

Yêu cầu này cần được uỷ quyền với ít nhất một trong các phạm vi sau (đọc thêm về quy trình xác thực và uỷ quyền).

Phạm vi
https://www.googleapis.com/auth/analytics.edit
https://www.googleapis.com/auth/analytics.readonly

Nội dung yêu cầu

Không cung cấp nội dung yêu cầu bằng phương thức này.

Phản hồi

Nếu thành công, phương thức này sẽ trả về nội dung phản hồi có cấu trúc như sau:

{
  "kind": "analytics#entityAdWordsLinks",
  "totalResults": integer,
  "startIndex": integer,
  "itemsPerPage": integer,
  "previousLink": string,
  "nextLink": string,
  "items": [
    management.webPropertyAdWordsLinks Resource
  ]
}
Tên tài sản Giá trị Nội dung mô tả Ghi chú
kind string Loại bộ sưu tập.
totalResults integer Tổng số kết quả cho truy vấn, bất kể số lượng kết quả trong phản hồi.
startIndex integer Chỉ mục bắt đầu của các mục nhập, là 1 theo mặc định hoặc được chỉ định khác bởi tham số truy vấn chỉ mục bắt đầu.
itemsPerPage integer Số mục nhập tối đa mà phản hồi có thể chứa, bất kể số lượng mục nhập thực tế được trả về. Giá trị của nó dao động từ 1 đến 1000 với giá trị là 1000 theo mặc định hoặc được chỉ định bởi tham số truy vấn kết quả tối đa.
items[] list Danh sách các mối liên kết với Google Ads về thực thể.

Ví dụ

Lưu ý: Các đoạn mã mẫu của phương thức này không phải là ví dụ cho mọi ngôn ngữ lập trình được hỗ trợ (xem trang thông tin về các thư viện dùng cho ứng dụng để biết danh sách các ngôn ngữ được hỗ trợ).

Java

Sử dụng thư viện ứng dụng Java.

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

/*
 * Example #1:
 * Requests a list of all Google Ads links for the authorized user.
 */
try {
  EntityAdWordsLinks adWordsLinks = analytics.management().
      webPropertyAdWordsLinks().list("123456", "UA-123456-1").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 adWordsLinks object.
 * The following code shows how to iterate through them.
 */
for (EntityAdWordsLink link : adWordsLinks.getItems()) {
  System.out.println("Link Id = " + link.getId());
  System.out.println("Link Kind = " + link.getKind());
  System.out.println("Link Name = " + link.getName());

  // Get the web property reference from the entity.
  WebPropertyRef property  = link.getEntity().getWebPropertyRef();
  System.out.println("Property Id = " + property.getId());
  System.out.println("Property Kind = " + property.getKind());
  System.out.println("Property Name = " + property.getName());
  System.out.println("Property Account Id = " + property.getAccountId());

  // Get the Google Ads accounts.
  List<AdWordsAccount> adWordsAccounts = link.getAdWordsAccounts();
  for (AdWordsAccount account : adWordsAccounts) {
    System.out.println("Account Kind = " + account.getKind());
    System.out.println("Account Id = " + account.getCustomerId());
    System.out.println("Auto Tagging Enabled = " + account.getAutoTaggingEnabled());
  }
}

1.199

Sử dụng thư viện ứng dụng PHP.

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

/**
 * Example #1:
 * Requests a list of all Google Ads links for the authorized user.
 */
try {
  $adWordsLinks = $analytics->management_webPropertyAdWordsLinks
      ->listManagementwebPropertyAdWordsLinks('123456', 'UA-123456-1');

} 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 adWordsLinks object.
 * The following code shows how to iterate through them.
 */
foreach ($adWordsLinks->getItems() as $link) {
  $html = <<<HTML
<pre>
Link Id = {$link->getId()}
Link Kind = {$link->getKind()}
Link Name = {$link->getName()}

HTML;

  // Get the web property reference from the entity.
  $property = $link->getEntity()->getWebPropertyRef();
  $html = <<<HTML
Property Id = {$property->getId()}
Property Kind = {$property->getKind()}
Property Name = {$property->getName()}
Property Account Id = {$property->getAccountId()}

HTML;

  // Get the Google Ads accounts.
  foreach ($link->getAdWordsAccounts as $account) {
    $html = <<<HTML
Account Kind = {$account->getKind()}
Account Id = {$account->getCustomerId()}
Auto Tagging Enabled = {$account->getAutoTaggingEnabled()}
HTML;
  }


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

Python

Sử dụng thư viện ứng dụng Python.

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

# Example #1:
# Requests a list of all Google Ads links for the authorized user.
try:
  adWordsLinks = analytics.management().webPropertyAdWordsLinks().list(
      accountId='123456',
      webPropertyId='UA-123456-1'
  ).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 adWordsLinks object.
# The following code shows how to iterate through them.
for link in adWordsLinks.get('items', []):
  print 'Link Id = %s' % link.get('id')
  print 'Link Kind = %s' % link.get('kind')
  print 'Link Name = %s' % link.get('name')

  # Get the property reference from the entity.
  property = link.get('entity', {}).get('webPropertyRef', {})
  print 'Property Id = %s' % property.get('id')
  print 'Property Kind = %s' % property.get('kind')
  print 'Property Name = %s' % property.get('name')
  print 'Property Account id = %s' % property.get('accountId')

  # Get the Google Ads accounts.
  adWordsAccounts = link.get('adWordsAccounts', [])
  for account in adWordsAccounts:
    print 'Account Id = %s' % account.get('id')
    print 'Account Kind = %s' % account.get('kind')
    print 'Auto Tagging Enabled = %s' % account.get('autoTaggingEnabled')

JavaScript

Sử dụng thư viện ứng dụng JavaScript.

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

/*
 * Example 1:
 * Requests a list of all Google Ads links for the authorized user.
 */
function listAdWordsLinks() {
  var request = gapi.client.analytics.management.webPropertyAdWordsLinks.list({
    'accountId': '123456',
    'webPropertyId': 'UA-123456-1'
  });
  request.execute(printViews);
}

/*
 * Example 2:
 * The results of the list method are passed as the results object.
 * The following code shows how to iterate through them.
 */
function printViews(results) {
  if (results && !results.error) {
    var adWordsLinks = results.items;
    for (var i = 0, link; link = adWordsLinks[i]; i++) {

      console.log('Link Id: ' + link.id);
      console.log('Link Kind: ' + link.kind);
      console.log('Link Name: ' + link.name);

      // Get the property reference from the entity.
      var property = link.entity.webPropertyRef;
      console.log('Property Id: ' + property.id);
      console.log('Property Kind: ' + property.kind);
      console.log('Property Name: ' + property.name);
      console.log('Property Account id: ' + property.accountId);

      // Get the Google Ads accounts.
      var adWordsAccounts = link.adWordsAccounts;
      for (var j = 0, account; account = adWordsAccounts[j]; j++) {
        console.log('Account Id: ' + account.customerId);
        console.log('Account Kind: ' + account.kind);
        console.log('Auto Tagging Enabled: ' + account.autoTaggingEnabled);
      }
    }
  }
}

Hãy dùng thử!

Sử dụng APIs Explorer bên dưới để gọi phương thức này trên dữ liệu trực tiếp và xem phản hồi. Ngoài ra, hãy dùng thử Trình khám phá độc lập.