您可以使用 Merchant Accounts API 查看您有权访问的账号(包括子账号)的过滤列表。您可以按显示名称和与其他账号的关系进行过滤。例如,您可以过滤出显示名称包含字符串 "store"
且关联状态为 PENDING
的账号,以查看尚未接受账号关联请求的所有商店。
如需查看您的所有子账号,请调用 accounts.v1beta.accounts.listSubAccounts
。
如需查看您有权访问的所有账号(包括子账号和将您列为 User
的所有账号)的过滤列表,请调用 accounts.v1beta.accounts.list
并在 filter
字段中指定过滤条件。
如需详细了解 filter
字段的语法,请参阅过滤条件语法参考文档。
您可以使用以下类型的过滤条件:
账号过滤条件
您可以使用以下字段在 account
级别进行过滤:
accountName
:按account
资源的accountName
进行过滤。relationship(...)
:按账号与其他账号的关系类型进行过滤。您可以在一个请求中包含多个relationship(...)
过滤条件。
关系过滤条件
您可以使用 relationship(...)
函数根据以下条件进行过滤:
providerId
:服务提供商的商家 ID。例如,如果过滤条件应仅返回由account/123
提供服务的账号,请使用providerId = 123
。accountIdAlias:
为关联配置的账号 ID 别名。service(...)
:在这种关系中提供的服务。您可以在一个relationship(...)
函数中添加多个service(...)
函数。
服务过滤条件
您可以使用 service(...)
函数根据账号关系的状态以及这些关系提供的服务类型进一步过滤账号:
externalAccountId
:服务提供商为其提供服务的账号的外部账号 ID。handshakeState
:两个账号之间的服务协议状态。接受以下值:PENDING
APPROVED
type:
提供商提供的服务类型。接受以下值:ACCOUNT_MANAGEMENT
提供商管理账号。ACCOUNT_AGGREGATION
提供商是该账号的集合商家。
示例
以下是一些您可以尝试的过滤条件示例。
过滤出显示名称包含“商店”且提供商 ID 为“123”的账号:
accountName = "*store*" AND relationship(providerId = 123)
过滤出账号“123”的所有子账号:
relationship(providerId = 123 AND service(type = "ACCOUNT_AGGREGATION"))
过滤出已获批准的账号管理服务的账号:
relationship(service(handshakeState = "APPROVED" AND type = "ACCOUNT_MANAGEMENT"))
过滤出具有特定别名的关联,并且该关联具有具有特定外部账号 ID 的服务的账号。
relationship(accountIdAlias = "alias" AND service(externalAccountId = "extAcctId"))
以下示例演示了如何使用 ListAccountsRequest
软件包检索经过过滤的账号列表。
Java
public static void filterAccounts(Config config) throws Exception {
// Obtains OAuth token based on the user's configuration.
GoogleCredentials credential = new Authenticator().authenticate();
// Creates service settings using the credentials retrieved above.
AccountsServiceSettings accountsServiceSettings =
AccountsServiceSettings.newBuilder()
.setCredentialsProvider(FixedCredentialsProvider.create(credential))
.build();
// Calls the API and catches and prints any network failures/errors.
try (AccountsServiceClient accountsServiceClient =
AccountsServiceClient.create(accountsServiceSettings)) {
// Filter for accounts with display names containing "store" and a provider with the ID "123":
String filter = "accountName = \"*store*\" AND relationship(providerId = 123)";
// Filter for all subaccounts of account "123":
// String filter2 = "relationship(callerHasAccessToProvider() AND providerId = 123 AND
// service(type = \"ACCOUNT_AGGREGATION\"))";
// String filter3 = "relationship(service(handshakeState = \"APPROVED\" AND type =
// \"ACCOUNT_MANAGEMENT\") AND providerId = 123)";
ListAccountsRequest request = ListAccountsRequest.newBuilder().setFilter(filter).build();
System.out.println("Sending list accounts request with filter:");
ListAccountsPagedResponse response = accountsServiceClient.listAccounts(request);
int count = 0;
// Iterates over all rows in all pages and prints the sub-account
// in each row.
// `response.iterateAll()` automatically uses the `nextPageToken` and recalls the
// request to fetch all pages of data.
for (Account account : response.iterateAll()) {
System.out.println(account);
count++;
}
System.out.print("The following count of elements were returned: ");
System.out.println(count);
} catch (Exception e) {
System.out.println(e);
}
}
后续步骤
- 如需详细了解如何过滤账号,请参阅过滤条件语法。