구성

Ads API 클라이언트 라이브러리는 라이브러리 동작을 맞춤설정하는 데 사용할 수 있는 몇 가지 구성 설정을 제공합니다.

구성 파일

클라이언트를 인스턴스화할 때 사용할 googleads.properties 파일을 지정할 수 있습니다.

인스턴스화할 때 인수를 사용하지 않는 경우:

my $api_client = Google::Ads::GoogleAds::Client->new();

그러면 라이브러리는 HOME 디렉터리에서 파일을 찾습니다.

또는 경로를 지정할 수 있습니다.

my $properties_file = "/path/to/googleads.properties";

my $api_client = Google::Ads::GoogleAds::Client->new({
  properties_file => $properties_file
});

이 경우 클라이언트는 해당 파일 경로에서 파일을 찾습니다.

이 파일을 생성하는 가장 쉬운 방법은 GitHub 저장소에서 googleads.properties를 복사하고 클라이언트 ID, 클라이언트 보안 비밀번호, 갱신 토큰을 포함하도록 수정하는 것입니다.

동적 구성

라이브러리를 인스턴스화할 때 또는 그 이후에 구성을 동적으로 설정할 수 있습니다.

my $api_client = Google::Ads::GoogleAds::Client->new({
  developer_token   => "INSERT_DEVELOPER_TOKEN_HERE",
  login_customer_id => "INSERT_LOGIN_CUSTOMER_ID_HERE"
});

인스턴스화한 후에도 구성을 수정할 수 있습니다.

$api_client->set_login_customer_id("INSERT_LOGIN_CUSTOMER_ID_HERE");

API Client에서 OAuth2ApplicationsHandler 객체를 가져오고 런타임 시 클라이언트 ID, 클라이언트 보안 비밀번호, 갱신 토큰을 변경할 수도 있습니다.

my $oauth2_applications_handler = $api_client->get_oauth2_applications_handler();
$oauth2_applications_handler->set_client_id("INSERT_CLIENT_ID");
$oauth2_applications_handler->set_client_secret("INSERT_CLIENT_SECRET");
$oauth2_applications_handler->set_refresh_token("INSERT_REFRESH_TOKEN");

구성 환경 변수

클라이언트를 인스턴스화할 때 환경 변수에서 일부 구성 설정을 지정할 수 있습니다 (전체 목록 참고).

클라이언트 모듈은 환경 변수에서 값을 로드하는 configure_from_environment_variables 함수를 제공합니다.

# Get the Google Ads Client. By default, any credentials will be read from
# ~/googleads.properties, or, if set, from the file specified in the
# GOOGLE_ADS_CONFIGURATION_FILE_PATH environment variable.
my $api_client = Google::Ads::GoogleAds::Client->new();

# Load the configuration from any set environment variables.
$api_client->configure_from_environment_variables();

구성 필드

구성 속성은 다음 필드를 지원합니다.

OAuth2ApplicationsHandler에 유지되는 필드:

  • client_id: OAuth2 클라이언트 ID입니다.
  • client_secret: OAuth2 클라이언트 보안 비밀번호입니다.
  • refresh_token: OAuth2 갱신 토큰입니다.

API 클라이언트에 유지되는 필드:

  • developer_token: API에 액세스하기 위한 개발자 토큰입니다.
  • login_customer_id: login-customer-id 문서를 참조하세요.
  • proxy: 인터넷 연결에 사용되는 프록시 서버 URL입니다.