Accounts: list

ต้องมีการให้สิทธิ์

แสดงบัญชี GTM ทั้งหมดที่ผู้ใช้มีสิทธิ์เข้าถึง ลองใช้เลยหรือดูตัวอย่าง

ส่งคำขอ

คำขอ HTTP

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

การให้สิทธิ์

คำขอนี้ต้องได้รับสิทธิ์อย่างน้อย 1 ขอบเขตต่อไปนี้ (อ่านเพิ่มเติมเกี่ยวกับการตรวจสอบสิทธิ์และการให้สิทธิ์)

ขอบเขต
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
  ]
}
ชื่อพร็อพเพอร์ตี้ ค่า คำอธิบาย Notes
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 ด้านล่างเพื่อเรียกใช้เมธอดนี้กับข้อมูลแบบเรียลไทม์และดูการตอบสนอง