AdWords 关联:update

需要授权

更新现有的网络媒体资源-AdWords 关联。 立即试用查看示例

请求

HTTP 请求

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

参数

参数名称 说明
路径参数
accountId string 给定网络媒体资源所属帐户的 ID。
webPropertyAdWordsLinkId string 网络媒体资源-AdWords 关联 ID。
webPropertyId string 要为其提取 AdWords 关联的网络媒体资源 ID。

授权

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

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

请求正文

在请求正文中提供一个具备以下属性的“AdWords 关联”资源

属性名称 说明 备注
必需属性
adWordsAccounts[] list AdWords 客户帐户列表。不可以是 MCC 帐户。在创建 AdWords 关联时,此字段是必填字段。此字段不能为空。 可写入
adWordsAccounts[].customerId string 客户 ID。在创建 AdWords 关联时,此字段是必填字段。
name string 关联的名称。在创建 AdWords 关联时,此字段是必填字段。 可写入

响应

如果成功,此方法将在响应正文中返回一个“AdWords 关联”资源

示例

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

Java

使用 Java 客户端库

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

/*
 * This request updates an existing AdWords Link.
 */

// Construct a list of AdWordsAccounts.
AdWordsAccount adWordsAccount = new AdWordsAccount();
adWordsAccount.setCustomerId("123-456-7890");
List<AdWordsAccount> adWordsAccounts = Arrays.asList(adWordsAccount);

// Construct the body of the request.
EntityAdWordsLink adWordsLink = new EntityAdWordsLink();
adWordsLink.setAdWordsAccounts(adWordsAccounts);
adWordsLink.setName("AdWords Link");

try{
  analytics.management().webPropertyAdWordsLinks().update("123456",
      "UA-123456-1", "AABBCCDDEEFFGG", adWordsLink).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 AdWords Links Developer Guide for details.
 */

/**
 * This request updates an existing AdWords Link.
 */

// Construct an AdWords account object.
$adWordsAccount = new Google_Service_Analytics_AdWordsAccount();
$adWordsAccount->setCustomerId("123-456-7890");

// Construct the body of the request.
$adWordsLink = new Google_Service_Analytics_EntityAdWordsLink();
$adWordsLink->setName('AdWords Link');
$adWordsLink->setAdWordsAccounts(array($adWordsAccount));

try {
  $analytics->management_webPropertyAdWordsLinks->update('123456',
      'UA-123456-1', 'AABBCCDDEEFFGG', $adWordsLink);

} 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 AdWords Links Developer Guide for details.

# This request updates an existing AdWords Link.
try:
  analytics.management().webPropertyAdWordsLinks().update(
      accountId='123456',
      webPropertyId='UA-123456-1',
      webPropertyAdWordsLinkId='AABBCCDDEEFFGG',
      body={
          'adWordsAccounts': [
              {
                  'customerId': '123-456-7890'
              }
          ],
          'name': 'AdWords Link'
      }
  ).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 AdWords Links Developer Guide for details.
 */

/*
 * This request updates an existing AdWords Link.
 */
function updateAdWordsLink() {
  var request = gapi.client.analytics.management.webPropertyAdWordsLinks.update(
    {
      'accountId': '123456',
      'webPropertyId': 'UA-123456-1',
      'webPropertyAdWordsLinks': '11112222233334444',
      'resource': {
        'adWordsAccounts': [ { 'customerId': '123-456-7890'} ],
        'name': 'Updated AdWords Link'
      }
    });
  request.execute(function (response) { // Handle the response. });
}

试试看!

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