이 페이지에서는 계정을 필터링하는 데 사용해야 하는 구문을 설명합니다.
구문
정수가 아닌 모든 값은 큰따옴표 (")로 묶어야 합니다. 특정 필드에서 허용되는 값을 알아보려면 해당 필드의 참조 문서를 참고하세요.
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*"은 'storeFoo'와 같이 foo이 포함된 accountName이 있는 모든 계정을 반환합니다.
!= 및 *를 사용하여 특정 시퀀스가 포함되지 않은 값을 필터링할 수 있습니다. 예를 들어 accountName != "*foo*"는 foo가 포함되지 않은 accountName가 있는 모든 계정을 반환합니다.
추가 공백은 무시됩니다. 예를 들어 foo AND bar는 foo
AND bar와 동일합니다.
다음은 account.list 메서드를 사용하여 계정을 필터링하는 몇 가지 예입니다.
'* 'Store'가 포함된 모든 MCA 하위 계정
accountName = "*store*" AND relationship(service(type = "ACCOUNT_AGGREGATION"))
- 제공업체 123456에서 관리하는 모든 계정
relationship(service(type = "ACCOUNT_MANAGEMENT") AND providerId = 123456)
- 공급자 123456에게 초대를 보냈거나 이 공급자의 초대를 수락해야 하는 모든 계정
relationship(service(handshakeState = "PENDING" AND type ="ACCOUNT_MANAGEMENT")
AND providerId = 123456)
요청을 하는 사용자가 액세스할 수 있는 계정을 필터링하려면 다음 샘플과 같이 google.shopping.merchant.accounts.v1.ListAccountsRequest 메서드를 사용하세요.
자바
import com.google.api.gax.core.FixedCredentialsProvider;
import com.google.auth.oauth2.GoogleCredentials;
import com.google.shopping.merchant.accounts.v1.Account;
import com.google.shopping.merchant.accounts.v1.AccountsServiceClient;
import com.google.shopping.merchant.accounts.v1.AccountsServiceClient.ListAccountsPagedResponse;
import com.google.shopping.merchant.accounts.v1.AccountsServiceSettings;
import com.google.shopping.merchant.accounts.v1.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
: " = " | " != "
;