本頁說明篩選帳戶時必須使用的語法。
語法
除了整數以外,所有值都必須以雙引號 (「」) 括住。如要瞭解特定欄位接受的值,請參閱該欄位的參考文件。
您可以使用 AND
在同一個查詢中篩選多個欄位。您也可以使用 AND
組合多個 relationship(...)
和 service(...)
篩選器。以下是結合多個 relationship(...)
和 service(...)
篩選器的範例:
(relationship(service(type = "ACCOUNT_MANAGEMENT") AND service(handshakeState = "PENDING"))) OR (accountName = "store" AND relationship(...))
這個範例會傳回下列帳戶:
所有與其他帳戶建立帳戶管理關係,且有其他待接受關係的帳戶。
所有顯示名稱為
"store"
且與其他帳戶有關係的帳戶。
您無法使用 AND
篩選同一個欄位中的多個值。舉例來說,您無法使用 accountName = "*A*" AND accountName = "*B*"
。
您可以使用 OR
在同一個查詢中篩選兩個欄位。請使用括號將 OR
運算子兩側的篩選條件括起來。例如:(accountName = "storeA") OR (accountName = "storeB")
您只能使用 OR
合併兩個欄位。例如,您無法使用 (accountName = "storeA") OR (accountName = "storeB") OR (accountName =
"storeC")
。
除了 AND
和 OR
運算子,以及 relationship(...)
和 service(...)
等函式呼叫之外,不允許使用括號。
針對 accountName
和 accountIdAlias
等字串欄位,您可以將序列括在星號 (*
) 中,篩選出含有特定字詞或字元序列的值。舉例來說,accountName = "*foo*"
會傳回所有 accountName
包含 foo
的帳戶,例如「storeFoo」。
您可以使用 !=
和 *
,篩選不含特定序列的值。舉例來說,accountName != "*foo*"
會傳回所有 accountName
不含 foo
的帳戶。
系統會忽略多餘的空格。舉例來說,foo AND bar
等同於 foo
AND bar
。
如要篩選提出要求的使用者可存取的帳戶,您可以使用 google.shopping.merchant.accounts.v1beta.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);
}
}
規格
篩選器遵循 AIP 篩選器規格的子集,以及其正式 EBNF 文法:
filter
: accountFilterDisj
| accountFilterConj
;
accountFilterDisj
: "(" accountFilterConj " OR " accountFilterConj ")"
;
accountFilterConj
: accountFilter {" AND " accountFilter}
;
accountFilter
: displayNameFilter | relationshipFn
;
displayNameFilter
: "displayName" comparator value
;
relationshipFn
: "relationship(" relationshipConj ")"
;
relationshipConj
: relationshipFilter {" AND " relationshipFilter}
;
relationshipFilter
: "providerId = " numValue
| "accountIdAlias" comparator value
| serviceFn
;
serviceFn
: "service(" serviceConj ")"
;
serviceConj
: serviceFilter {" AND " serviceFilter}
;
serviceFilter
: "externalAccountId" comparator value
| "handshakeState = " value
| "type = " value
;
comparator
: " = " | " != "
;