Accounts: list

Autorisierung erforderlich

Listet alle Konten auf, auf die der Nutzer Zugriff hat. Probieren Sie es gleich aus oder sehen Sie sich ein Beispiel an.

Bei dieser Methode werden zusätzlich zu den Standardparametern die in der Parametertabelle aufgeführten Parameter unterstützt.

Anfragen

HTTP-Anfrage

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

Parameter

Parametername Wert Beschreibung
Optionale Abfrageparameter
max-results integer Die maximale Anzahl von Konten, die in dieser Antwort enthalten sein können.
start-index integer Ein Index des ersten abzurufenden Kontos. Verwenden Sie diesen Parameter als Paginierungsmechanismus zusammen mit dem Parameter max-results.

Autorisierung

Diese Anfrage benötigt eine Autorisierung mit mindestens einem der folgenden Bereiche (weitere Informationen zu Authentifizierung und Autorisierung).

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

Anfragetext

Mit dieser Methode keinen Anfragetext bereitstellen.

Antwort

Bei Erfolg gibt diese Methode einen Antworttext mit der folgenden Struktur zurück:

{
  "kind": "analytics#accounts",
  "username": string,
  "totalResults": integer,
  "startIndex": integer,
  "itemsPerPage": integer,
  "previousLink": string,
  "nextLink": string,
  "items": [
    management.accounts Resource
  ]
}
Name der Eigenschaft Wert Beschreibung Hinweise
kind string Sammlungstyp. Der Wert ist „analytics#accounts“.
username string E-Mail-ID des authentifizierten Nutzers
totalResults integer Die Gesamtzahl der Ergebnisse für die Abfrage, unabhängig von der Anzahl der Ergebnisse in der Antwort.
startIndex integer Der Startindex der Einträge, der standardmäßig 1 ist oder anderweitig durch den Abfrageparameter start-index angegeben wird.
itemsPerPage integer Die maximale Anzahl von Einträgen, die die Antwort enthalten kann, unabhängig von der tatsächlichen Anzahl der zurückgegebenen Einträge. Der Wert reicht von 1 bis 1.000, wobei der Wert standardmäßig 1.000 ist oder anderweitig durch den Abfrageparameter max-results angegeben wird.
items[] list Eine Liste mit Konten.

Beispiele

Hinweis: Bei den für diese Methode verfügbaren Codebeispielen sind nicht alle unterstützten Programmiersprachen vertreten. Eine Liste der unterstützten Sprachen finden Sie auf der Seite für Clientbibliotheken.

Java

Verwendet die Java-Clientbibliothek.

/**
 * 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

Verwendet die PHP-Clientbibliothek.

/**
 * 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

Verwendet die Python-Clientbibliothek.

# 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

Es wird die JavaScript-Clientbibliothek verwendet.

/*
 * 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);
    }
  }
}

Jetzt testen

Verwenden Sie den unten angegebenen APIs Explorer, um diese Methode für Livedaten aufzurufen und die Antwort einzusehen. Probieren Sie alternativ den eigenständigen Explorer aus.