라이브러리는 System.getProperty("user.home") + "/ads.properties"
에서 구성 파일을 찾습니다. 다음 메커니즘 중 하나를 사용하여 GoogleAdsClient
를 구성할 때 런타임에 이 경로와 파일 이름을 재정의할 수 있습니다.
fromPropertiesFile(PATH_TO_CONFIG_FILE)
를 호출합니다. 여기서PATH_TO_CONFIG_FILE
은 구성 파일의 경로 및 파일 이름입니다.- 환경 변수
GOOGLE_ADS_CONFIGURATION_FILE_PATH
를 구성 파일의 경로 및 파일 이름으로 설정한 다음fromPropertiesFile()
를 호출합니다.
구성 파일의 형식은 키-값 쌍의 Java 속성 파일 형식입니다. 지원되는 키는 선택한 인증 흐름에 따라 다릅니다.
데스크톱 및 웹 애플리케이션 흐름에 지원되는 키
데스크톱 또는 웹 애플리케이션 흐름을 사용하는 경우 지원되는 키는 다음과 같습니다.
# Credential for accessing Google's OAuth servers.
# Provided by console.cloud.google.com.
api.googleads.clientId=INSERT_CLIENT_ID_HERE
# Credential for accessing Google's OAuth servers.
# Provided by console.cloud.google.com.
api.googleads.clientSecret=INSERT_CLIENT_SECRET_HERE
# Renewable OAuth credential associated with 1 or more Google Ads accounts.
api.googleads.refreshToken=INSERT_REFRESH_TOKEN_HERE
# Token which provides access to the Google Ads API in general. It does not
# grant access to any particular ad account (OAuth is used for this purpose).
api.googleads.developerToken=INSERT_DEVELOPER_TOKEN_HERE
# Required for manager accounts only: Specify the login customer ID used to
# authenticate API calls. This will be the customer ID of the authenticated
# manager account. You can also specify this later in code if your application
# uses multiple manager account + OAuth pairs.
#
# api.googleads.loginCustomerId=INSERT_LOGIN_CUSTOMER_ID_HERE
# Only required if explicitly instructed by the service documentation.
# api.googleads.linkedCustomerId=INSERT_LINKED_CUSTOMER_ID_HERE
# Maximum allowed response payload size, in bytes.
# Customize this to allow response sizes for GoogleAdsService.search and
# GoogleAdsService.searchStream API calls to exceed the default limit of 64MB.
# api.googleads.maxInboundMessageBytes=INSERT_MAX_INBOUND_MESSAGE_BYTES_HERE
서비스 계정에서 지원되는 키
서비스 계정 흐름을 사용하는 경우 지원되는 키는 다음과 같습니다.
# Path to the service account secrets file in JSON format.
# Provided by console.cloud.google.com.
api.googleads.serviceAccountSecretsPath=INSERT_PATH_TO_JSON_HERE
# Email address of the user to impersonate.
# This should be a user who has access to your Google Ads account and is in the same
# Google Apps Domain as the service account.
api.googleads.serviceAccountUser=INSERT_USER_EMAIL_ADDRESS_HERE
# Token which provides access to the Google Ads API in general. It does not
# grant access to any particular ad account (OAuth is used for this purpose).
api.googleads.developerToken=INSERT_DEVELOPER_TOKEN_HERE
# Required for manager accounts only: Specify the login customer ID used to
# authenticate API calls. This will be the customer ID of the authenticated
# manager account. You can also specify this later in code if your application
# uses multiple manager account + OAuth pairs.
#
# api.googleads.loginCustomerId=INSERT_LOGIN_CUSTOMER_ID_HERE
환경 변수 사용
이 라이브러리는 모든 Google Ads API 클라이언트 라이브러리에 공통적인 환경 변수를 모두 지원합니다. 아래 표에는 각 구성 파일 속성에 해당하는 환경 변수가 나와 있습니다.
구성 파일 속성 | 환경 변수 |
---|---|
api.googleads.developerToken |
GOOGLE_ADS_DEVELOPER_TOKEN |
api.googleads.clientId |
GOOGLE_ADS_CLIENT_ID |
api.googleads.clientSecret |
GOOGLE_ADS_CLIENT_SECRET |
api.googleads.refreshToken |
GOOGLE_ADS_REFRESH_TOKEN |
api.googleads.serviceAccountSecretsPath |
GOOGLE_ADS_JSON_KEY_FILE_PATH |
api.googleads.serviceAccountUser |
GOOGLE_ADS_IMPERSONATED_EMAIL |
api.googleads.loginCustomerId |
GOOGLE_ADS_LOGIN_CUSTOMER_ID |
api.googleads.linkedCustomerId |
GOOGLE_ADS_LINKED_CUSTOMER_ID |
api.googleads.maxInboundMessageBytes |
GOOGLE_ADS_MAX_INBOUND_MESSAGE_BYTES |
적절한 환경 변수를 설정했으면 빌더에서 fromEnvironment()
를 호출하여 GoogleAdsClient
를 구성합니다.
GoogleAdsClient googleAdsClient = GoogleAdsClient.newBuilder()
.fromEnvironment()
.build();
구성 접근 방식 결합
GoogleAdsClient
및 빌더는 다양한 구성 전략을 결합하는 것을 지원합니다. 예를 들어 다음 스니펫을 사용하여 환경 변수를 사용하여 인스턴스의 사용자 인증 정보와 다른 속성의 속성 파일을 구성할 수 있습니다.
GoogleAdsClient googleAdsClient = GoogleAdsClient.newBuilder()
.fromEnvironment()
.fromPropertiesFile()
.build();
이 예에서 클라이언트 라이브러리는 환경 변수와 속성 파일의 항목을 통해 모두 정의된 모든 속성에 속성 파일의 값을 사용합니다. 반대 동작을 사용하려면 fromEnvironment()
전에 fromPropertiesFile()
를 호출하면 됩니다.
build()
를 호출하기 전에 빌더의 다른 구성 메서드를 사용하여 런타임 시 추가 변경사항을 적용할 수 있습니다.