Variables: list

Wymaga autoryzacji

Wyświetla listę wszystkich zmiennych Menedżera tagów Google w kontenerze. Wypróbuj lub zobacz przykład.

Prośba

Żądanie HTTP

GET https://www.googleapis.com/tagmanager/v1/accounts/accountId/containers/containerId/variables

Parametry

Nazwa parametru Wartość Opis
Parametry ścieżki
accountId string Identyfikator konta Menedżera tagów Google.
containerId string Identyfikator kontenera Menedżera tagów Google.

Upoważnienie

To żądanie wymaga autoryzacji z co najmniej jednym z poniższych zakresów (więcej informacji o uwierzytelnianiu i autoryzacji).

Zakres
https://www.googleapis.com/auth/tagmanager.readonly
https://www.googleapis.com/auth/tagmanager.edit.containers

Treść żądania

Nie podawaj treści żądania z tą metodą.

Odpowiedź

Jeśli operacja się uda, metoda zwróci odpowiedź w następującej strukturze:

{
  "variables": [
    accounts.containers.variables Resource
  ]
}
nazwa usługi, Wartość Opis Uwagi
variables[] list Wszystkie zmienne Menedżera tagów Google w kontenerze Menedżera tagów Google.

Przykłady

Uwaga: dostępne dla tej metody przykłady kodu nie odzwierciedlają wszystkich obsługiwanych języków programowania. Listę obsługiwanych języków znajdziesz na stronie z bibliotekami klienta.

Java

Korzysta z biblioteki klienta Java.

/*
 * Note: This code assumes you have an authorized tagmanager service object.
 */

/*
 * This request lists variables for the authorized user.
 */
try {
  ListVariablesResponse variables = tagmanager.accounts().containers().
      variables().list("123456", "54321").execute();
} catch (GoogleJsonResponseException e) {
  System.err.println("There was a service error: "
      + e.getDetails().getCode() + " : "
      + e.getDetails().getMessage());
}

/*
 * The results of the list method are stored in the variables object.
 * The following code shows how to iterate through them.
 */
for (Variable variable: variables.getVariables()) {
  System.out.println("Account Id = " + variable.getAccountId());
  System.out.println("Container Id = " + variable.getContainerId());
  System.out.println("Variable Id = " + variable.getVariableId());
  System.out.println("Variable Name = " + variable.getName());
  System.out.println("Variable Type = " + variable.getType());
  System.out.println("Variable Notes = " + variable.getNotes());
  if (variable.getParameter() != null) {
    for (Parameter parameter : variable.getParameter()) {
      System.out.println("Parameter Type = " + parameter.getType());
      System.out.println("Parameter Key = " + parameter.getKey());
      System.out.println("Parameter Value = " + parameter.getValue());
    }
  }
  if (variable.getEnablingTriggerId() != null) {
    for (String enablingTriggerId : variable.getEnablingTriggerId()) {
      System.out.println("Enabling Trigger Id = " + enablingTriggerId);
    }
  }
  if (variable.getDisablingTriggerId() != null) {
    for (String disablingTriggerId : variable.getDisablingTriggerId()) {
      System.out.println("Disabling Trigger Id " + disablingTriggerId);
    }
  }
  System.out.println("Variable Fingerprint = "
      + variable.getFingerprint());
}

Python

Używa biblioteki klienta dla języka Python.

# Note: This code assumes you have an authorized tagmanager service object.

# This request lists variables for the authorized user.
try:
  variables = tagmanager.accounts().containers().variables().list(
      accountId='123456',
      containerId='54321'
  ).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))


# The results of the list method are stored in the variables object.
# The following code shows how to iterate through them.
for variable in variables.get('variables', []):
  print 'Account Id = %s' % variable.get('accountId')
  print 'Container Id = %s' % variable.get('containerId')
  print 'Variable Id = %s' % variable.get('variableId')
  print 'Variable Name = %s' % variable.get('name')
  print 'Variable Type = %s' % variable.get('type')
  print 'Variable notes = %s' % variable.get('notes')
  for parameter in variable.get('parameter', []):
    print 'Parameter Type = %s' % parameter.get('type')
    print 'Parameter Key = %s' % parameter.get('key')
    print 'Parameter Value = %s' % parameter.get('value')
  for enablingTrigerId in variable.get('enablingTrigerId', []):
    print 'Enabling Trigger Id = %s' % enablingTrigerId
  for disablingTriggerId in variable.get('disablingTriggerId', []):
    print 'Disabling Trigger Id = %s' % disablingTriggerId
  print 'Variable Fingerprint = %s\n\n' % variable.get('fingerprint')

Wypróbuj

Użyj Eksploratora interfejsów API poniżej, aby wywołać tę metodę na aktywnych danych i zobaczyć odpowiedź.