如何通过Google API获取所有品牌账户?
Great question! I’ve looked into this exact scenario before, and there is a valid API solution to pull all brand accounts linked to your Google account—here’s how it works:
Use the Google People API
This is the official, supported way to fetch brand account data for the authenticated user. You’ll need to call thepeople.getendpoint with thepersonFields=brandAccountsparameter to specifically request brand account information.Required Permissions
You’ll need to request theprofileOAuth scope (or the more specifichttps://www.googleapis.com/auth/userinfo.profile) during the authorization flow. This ensures your app has access to the user’s profile-associated brand accounts.Quick Code Example
Here’s a Python snippet to demonstrate the call (assuming you’ve already set up OAuth 2.0 credentials):from googleapiclient.discovery import build from google.oauth2.credentials import Credentials # Load your saved OAuth credentials creds = Credentials.from_authorized_user_file('token.json') people_service = build('people', 'v1', credentials=creds) # Fetch the user's brand accounts response = people_service.people().get( resourceName='people/me', personFields='brandAccounts' ).execute() # Extract and iterate through brand accounts brand_accounts = response.get('brandAccounts', []) for account in brand_accounts: print(f"Brand Account: {account['displayName']} | ID: {account['metadata']['source']['id']}")Key Notes
- Make sure you’ve enabled the Google People API in your Google Cloud Console project before making calls.
- The returned data matches what you see on
myaccount.google.com/brandaccounts—including display names, account IDs, and account types. - For Google Workspace users, you might need additional Admin SDK scopes if managing brand accounts for an organization, but for personal accounts, the People API is all you need.
内容的提问来源于stack exchange,提问作者Jeff I

