Accounts: list

Requiere autorización

Enumera todas las cuentas a las que el usuario tiene acceso. Pruébalo ahora y ve un ejemplo.

Además de los parámetros estándar, este método admite los parámetros enumerados en la tabla de parámetros.

Solicitud

Solicitud HTTP

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

Parámetros

Nombre del parámetro Valor Descripción
Parámetros de consulta opcionales
max-results integer La cantidad máxima de cuentas que se deben incluir en esta respuesta.
start-index integer Un índice de la primera cuenta que se recuperará. Usa 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).

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

Cuerpo de la solicitud

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

Respuesta

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

{
  "kind": "analytics#accounts",
  "username": string,
  "totalResults": integer,
  "startIndex": integer,
  "itemsPerPage": integer,
  "previousLink": string,
  "nextLink": string,
  "items": [
    management.accounts Resource
  ]
}
Nombre de la propiedad Valor Descripción Notas
kind string Tipo de colección. El valor es "analytics#accounts".
username string ID de correo electrónico del usuario autenticado
totalResults integer La cantidad total de resultados para la consulta, sin importar la cantidad 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 start-index lo especifica.
itemsPerPage integer El número máximo de entradas que puede contener la respuesta, sin importar el número real de entradas que se muestran. Su valor varía de 1 a 1,000 y tiene un valor predeterminado de 1,000, o lo especifica el parámetro de consulta max-results.
items[] list Una lista de cuentas.

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 Account Developer Guide for details.
 */

/**
 * Example #1:
 * Requests a list of all accounts for the authorized user.
 */
try {
  Accounts accounts = analytics.management.accounts.list().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 accounts object.
 * The following code shows how to iterate through them.
 */
for (Account account : accounts.getItems()) {
  System.out.println("Account ID: " + account.getId());
  System.out.println("Account Name: " + account.getName());
  System.out.println("Account Created: " + account.getCreated());
  System.out.println("Account Updated: " + account.getUpdated());
}

PHP

Usa la biblioteca cliente de PHP.

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

/**
 * Example #1:
 * Requests a list of all accounts for the authorized user.
 */
try {
  $accounts = $analytics->management_accounts->listManagementAccounts();
} 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 accounts object.
 * The following code shows how to iterate through them.
 */
foreach ($accounts->getItems() as $account) {
  $html = <<<HTML
<pre>
Account id   = {$account->getId()}
Account name = {$account->getName()}
Created      = {$account->getCreated()}
Updated      = {$account->getUpdated()}
</pre>
HTML;
  print $html;
}

Python

Usa la biblioteca cliente de Python.

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

# Example #1:
# Requests a list of all accounts for the authorized user.
try:
  accounts = analytics.management().accounts().list().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 accounts object.
# The following code shows how to iterate through them.
for account in accounts_response.get('items', []):
  print 'Account ID      = %s' % account.get('id')
  print 'Account Name    = %s' % account.get('name')
  print 'Created         = %s' % account.get('created')
  print 'Updated         = %s' % account.get('updated')

JavaScript

Usa la biblioteca cliente de JavaScript.

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

/*
 * Example 1:
 * Requests a list of all accounts for the authorized user.
 */
function listAccounts() {
  var request = gapi.client.analytics.management.accounts.list();
  request.execute(printAccounts);
}

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

Pruébala

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