需要授權
列出使用者可存取的所有 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 |
使用者可存取的 Google 代碼管理工具帳戶清單。 |
範例
注意:這個方法適用的程式語言眾多,我們只在此提供部分程式碼範例,完整的支援語言清單請參閱用戶端程式庫頁面。
Java
使用 Java 用戶端程式庫。
/* * 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()); }
Python
使用 Python 用戶端程式庫。
# 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,針對即時資料呼叫這個方法,然後查看回應。