Accounts: list

نیاز به مجوز دارد

تمام حساب‌های GTM را که کاربر به آنها دسترسی دارد فهرست می‌کند. اکنون آن را امتحان کنید یا نمونه ای را ببینید .

درخواست

درخواست HTTP

GET https://www.googleapis.com/tagmanager/v1/accounts

مجوز

این درخواست به مجوز حداقل با یکی از حوزه های زیر نیاز دارد ( در مورد احراز هویت و مجوز بیشتر بخوانید ).

محدوده
https://www.googleapis.com/auth/tagmanager.readonly
https://www.googleapis.com/auth/tagmanager.manage.accounts
https://www.googleapis.com/auth/tagmanager.edit.containers

درخواست بدن

با این روش بدنه درخواستی ارائه نکنید.

واکنش

در صورت موفقیت آمیز بودن، این روش یک بدنه پاسخ با ساختار زیر را برمی گرداند:

{
  "accounts": [
    accounts Resource
  ]
}
نام ملک ارزش شرح یادداشت
accounts[] list فهرست حساب‌های GTM که کاربر به آنها دسترسی دارد.

مثال ها

توجه: نمونه‌های کد موجود برای این روش همه زبان‌های برنامه‌نویسی پشتیبانی‌شده را نشان نمی‌دهند (برای فهرست زبان‌های پشتیبانی‌شده به صفحه کتابخانه‌های سرویس گیرنده مراجعه کنید).

جاوا

از کتابخانه سرویس گیرنده جاوا استفاده می کند.

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

/*
 * This request lists all accounts for the authorized user.
 */
try {
  ListAccountsResponse accounts = tagmanager.accounts().list().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 accounts object.
 * The following code show how to iterate through them.
 */
for (Account account : accounts.getAccounts()) {
  System.out.println("Account Id = " + account.getAccountId());
  System.out.println("Account Name = " + account.getName());
  System.out.println("Account Share Data = " + account.getShareData());
  System.out.println("Account Fingerprint = " + account.getFingerprint());
}

پایتون

از کتابخانه کلاینت پایتون استفاده می کند.

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

# This request lists all accounts for the authorized user.
try:
  accounts = tagmanager.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 dir(error)
  print ('There was an API error : %s : %s' %
         (error.resp.status, error.resp.reason))


# 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.get('accounts', []):
  print 'Account Id = %s' % account.get('accountId')
  print 'Account Name = %s' % account.get('name')
  print 'Account Share Data = %s' % account.get('shareData')
  print 'Account Fingerprint = %s' % account.get('fingerprint')

آن را امتحان کنید!

از APIs Explorer زیر برای فراخوانی این روش در داده‌های زنده و دیدن پاسخ استفاده کنید.