구성

라이브러리는 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()