Google Ads Links: list

Requiere autorización

Se muestran las vinculaciones webProperty-Google Ads de una propiedad web determinada. Pruébalo ahora y ve un ejemplo.

Solicitud

Solicitud HTTP

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

Parámetros

Nombre del parámetro Valor Descripción
Parámetros de ruta de acceso
accountId string Es el ID de la cuenta a la que pertenece la propiedad web determinada.
webPropertyId string ID de propiedad web para la que se recuperarán las vinculaciones de Google Ads.
Parámetros de consulta opcionales
max-results integer Es la cantidad máxima de vínculos webProperty-Google Ads que se deben incluir en esta respuesta.
start-index integer Un índice de la primera vinculación webProperty-Google Ads que se recuperará. Utiliza este parámetro como un mecanismo de paginación junto con el parámetro max-results.

Autorización

Esta solicitud requiere autorización con al menos uno de los siguientes alcances (obtén más información acerca de la autenticación y autorización).

Alcance
https://www.googleapis.com/auth/analytics.edit
https://www.googleapis.com/auth/analytics.readonly

Cuerpo de la solicitud

No proporciones un cuerpo de la solicitud con este método.

Respuesta

Si se aplica correctamente, este método muestra un cuerpo de respuesta con la siguiente estructura:

{
  "kind": "analytics#entityAdWordsLinks",
  "totalResults": integer,
  "startIndex": integer,
  "itemsPerPage": integer,
  "previousLink": string,
  "nextLink": string,
  "items": [
    management.webPropertyAdWordsLinks Resource
  ]
}
Nombre de la propiedad Valor Descripción Notas
kind string Tipo de colección.
totalResults integer El número total de resultados para la consulta, sin importar el número de resultados en la respuesta.
startIndex integer El índice de inicio de las entradas, que es 1 de forma predeterminada o que el parámetro de consulta del índice de inicio lo especifica.
itemsPerPage integer La cantidad máxima de entradas que puede contener la respuesta, sin importar la cantidad real de entradas que se muestran. Su valor varía entre 1 y 1,000, con un valor de 1,000 de forma predeterminada o especificado en el parámetro de consulta max-results.
items[] list Una lista de entidades vinculadas de Google Ads.

Ejemplos

Nota: Los ejemplos de código disponibles para este método no representan todos los lenguajes de programación admitidos (consulta la página de bibliotecas cliente para consultar una lista de lenguajes admitidos).

Java

Usa la biblioteca cliente de 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());
  }
}

PHP

Utiliza la biblioteca cliente 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

Usa la biblioteca cliente de 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

Usa la biblioteca cliente de 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);
      }
    }
  }
}

Pruébalo

Usa el Explorador de APIs que aparece a continuación para llamar a este método con los datos en tiempo real y ver la respuesta. También puedes probar el Explorador independiente.