需要授权
请求
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 账号的列表。 |
示例
注意:此方法的代码示例并未列出所有受支持的编程语言(请参阅客户端库页面,查看受支持的语言列表)。
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')
试试看!
请使用下面的 API Explorer 对实时数据调用此方法并查看响应。