이 페이지에서는 계정을 필터링하는 데 사용해야 하는 구문을 설명합니다.
구문
정수가 아닌 모든 값은 큰따옴표 (")로 묶어야 합니다. 특정 필드에서 허용하는 값을 알아보려면 해당 필드의 참조 문서를 참고하세요.
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*"
은 foo
가 포함된 accountName
(예: 'storeFoo')가 있는 모든 계정을 반환합니다.
!=
및 *
를 사용하여 특정 시퀀스가 포함되지 않은 값을 필터링할 수 있습니다. 예를 들어 accountName != "*foo*"
는 foo
가 포함되지 않은 accountName
가 있는 모든 계정을 반환합니다.
추가 공백은 무시됩니다. 예를 들어 foo AND bar
는 foo
AND bar
와 동일합니다.
요청하는 사용자가 액세스할 수 있는 계정을 필터링하려면 다음 샘플과 같이 google.shopping.merchant.accounts.v1beta.ListAccountsRequest
메서드를 사용하면 됩니다.
자바
import com.google.api.gax.core.FixedCredentialsProvider;
import com.google.auth.oauth2.GoogleCredentials;
import com.google.shopping.merchant.accounts.v1beta.Account;
import com.google.shopping.merchant.accounts.v1beta.AccountsServiceClient;
import com.google.shopping.merchant.accounts.v1beta.AccountsServiceClient.ListAccountsPagedResponse;
import com.google.shopping.merchant.accounts.v1beta.AccountsServiceSettings;
import com.google.shopping.merchant.accounts.v1beta.ListAccountsRequest;
import shopping.merchant.samples.utils.Authenticator;
import shopping.merchant.samples.utils.Config;
/** This class demonstrates how to filter the accounts the user making the request has access to. */
public class FilterAccountsSample {
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(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);
}
}
public static void main(String[] args) throws Exception {
Config config = Config.load();
filterAccounts(config);
}
}
사양
필터는 AIP 필터 사양의 하위 집합과 형식 EBNF 문법을 따릅니다.
filter
: accountFilterDisj
| accountFilterConj
accountFilterDisj
: "(" accountFilterConj " OR " accountFilterConj ")"
;
accountFilterConj
: accountFilter {" AND " accountFilter}
;
accountFilter
: accountNameFilter | capabilityFilter | relationshipFn
;
accountNameFilter
: "accountName" comparator value
;
capabilityFilter
: "capabilities:" capabilityValue
| "-capabilities:" capabilityValue
| "NOT capabilities:" capabilityValue
;
capabilityValue
: "CAN_UPLOAD_PRODUCTS"
;
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 = " handshakeState
| "type = " serviceType
;
handshakeState
: "PENDING"
| "APPROVED"
| "REJECTED"
;
serviceType
: "ACCOUNT_AGGREGATION"
| "ACCOUNT_MANAGEMENT"
;
comparator
: " = " | " != "
;