Google Ads API 클라이언트 라이브러리는 Google Ads API 기능의 개략적인 뷰와 기본 빌딩 블록을 제공하므로 앱을 더 쉽고 빠르게 개발할 수 있습니다. API를 처음 사용하는 경우 클라이언트 라이브러리로 시작하세요.
커뮤니티 라이브러리
오픈소스 커뮤니티에서 유지관리하는 라이브러리가 여러 개 있습니다. 관심 있는 개발자가 이러한 리소스를 찾을 수 있도록 이 목록을 유지합니다. Google에서는 이러한 라이브러리를 테스트하거나, 기여하거나, 유지관리하지 않습니다. 자체적으로 위험을 감수하고 사용하세요. 궁금한 점이 있으면 오픈소스 프로젝트 소유자에게 문의하세요.
누락된 라이브러리를 알고 있다면 페이지 상단의 의견 보내기를 클릭하여 알려주세요.
- Node.js: npm의
google-ads-api - Go: GitHub의
google-ads-pb
지원되는 API 버전
표에는 어떤 클라이언트 라이브러리가 어떤 API 버전과 호환되는지 나와 있습니다.
나열된 최소 클라이언트 라이브러리 버전은 주요 Google Ads API 출시 (예: v25)에 충분합니다. 부 버전의 필수 클라이언트 라이브러리 버전을 확인하려면 연결된 변경사항을 참고하세요.
자바
Google Ads API |
자바용 클라이언트 라이브러리 |
v25 |
Min: 44.0.0Max: - |
v24 |
Min: 43.0.0Max: - |
v23 |
Min: 42.0.0Max: - |
v22 |
Min: 41.0.0Max: - |
C#
Google Ads API |
.NET용 클라이언트 라이브러리 |
v25 |
Min: 26.1.0Max: - |
v24 |
Min: 25.3.0Max: - |
v23 |
Min: 25.1.0Max: - |
v22 |
Min: 24.1.0Max: - |
PHP
Google Ads API |
PHP용 클라이언트 라이브러리 |
v25 |
Min: 33.6.0Max: - |
v24 |
Min: 33.3.0Max: - |
v23 |
Min: 32.2.0Max: - |
v22 |
Min: 31.0.0Max: - |
Python
Google Ads API |
Python용 클라이언트 라이브러리 |
v25 |
Min: 31.2.0Max: - |
v24 |
Min: 30.1.0Max: - |
v23 |
Min: 29.2.0Max: - |
v22 |
Min: 28.1.0Max: 32.0.0
|
Ruby
Google Ads API |
Ruby용 클라이언트 라이브러리 |
v25 |
Min: 43.0.0Max: - |
v24 |
Min: 40.0.0Max: - |
v23 |
Min: 38.0.0Max: - |
v22 |
Min: 36.0.0Max: - |
Perl
Google Ads API |
Perl용 클라이언트 라이브러리 |
v25 |
Min: 33.0.0Max: - |
v24 |
Min: 32.0.0Max: - |
v23 |
Min: 31.0.0Max: - |
v22 |
Min: 29.0.0Max: - |
구성
각 Google Ads API 클라이언트 라이브러리는 동작을 맞춤설정하는 데 사용할 수 있는 다양한 구성 설정과 로드 방법을 제공합니다.
클라이언트 라이브러리를 구성하는 데 사용할 수 있는 표준 환경 변수는 다음과 같습니다.
- 클라이언트 라이브러리
GOOGLE_ADS_CONFIGURATION_FILE_PATH: 구성 파일의 경로입니다(Java (fromPropertiesFile()), Perl(Client->new()), PHP (fromFile()), Python (load_from_storage(),load_from_env()에서도 확인됨), Ruby(GoogleAdsClient.new)에서 명시적 경로 인수가 없는 구성 파일에서 로드할 때 자동으로 읽음..NET에서는config.TryLoadFromEnvironmentFilePath를 사용하여 이 변수를 명시적으로 로드하거나LoadFromSettingsJson,LoadFromConfigurationSection또는LoadFromConfigurationRoot를 사용하여 구성 파일을 로드함).
- OAuth2
- 애플리케이션 모드
GOOGLE_ADS_CLIENT_ID: 이 값을 OAuth2 클라이언트 ID로 설정합니다.GOOGLE_ADS_CLIENT_SECRET: 이 값을 OAuth2 클라이언트 보안 비밀번호로 설정합니다.GOOGLE_ADS_REFRESH_TOKEN: OAuth2 토큰을 재사용하려면 이 값을 미리 생성된 OAuth2 갱신 토큰으로 설정합니다. 이 설정은 선택사항입니다.
- 서비스 계정 모드
GOOGLE_ADS_JSON_KEY_FILE_PATH: 이 값을 OAuth2 JSON 키 파일의 경로로 설정합니다 (.NET에서GOOGLE_ADS_OAUTH2_MODE도SERVICE_ACCOUNT로 설정합니다.OAuth2Mode은APPLICATION으로 기본 설정되기 때문입니다.v32.1.0이전 PHP 버전이나 맞춤 범위를 사용하는 경우fromEnvironmentVariables()은 환경 변수에서 OAuth2 범위를 읽지 않으므로google_ads_php.ini에서[OAUTH2] scopes도 설정하거나withScopes()를 호출합니다).GOOGLE_ADS_IMPERSONATED_EMAIL: Google Workspace 도메인 전체 위임을 사용할 때 가장하는 계정의 이메일 주소로 이 값을 설정합니다. 이 설정은 선택사항입니다.
- 애플리케이션 기본 사용자 인증 정보 모드
GOOGLE_ADS_USE_APPLICATION_DEFAULT_CREDENTIALS: 애플리케이션 기본 사용자 인증 정보 (ADC)를 사용하여 인증하려면 이 값을true로 설정합니다. Javav41.1.0이상, Pythonv28.3.0이상, Rubyv36.1.0이상에서 지원됩니다(.NETv24.1.0이상에서는LoadFromEnvironmentVariables()가 접두사가 없는USE_APPLICATION_DEFAULT_CREDENTIALS변수를 대신 읽거나GoogleAdsConfig에UseApplicationDefaultCredentials = true을 설정합니다. PHP에서는 명시적 OAuth2 사용자 인증 정보가 설정되지 않은 경우OAuth2TokenBuilder이 ADC로 자동 대체됩니다. Perl은 ADC를 지원하지 않습니다).
- 애플리케이션 모드
- Google Ads API
GOOGLE_ADS_DEVELOPER_TOKEN: 최신 버전에서 선택사항 (Javav46.0.0이상, .NETv27.3.0이상, PHPv35.0.0이상, Pythonv32.0.0이상, Rubyv45.0.0이상, Perlv35.0.0이상) 개발자 토큰은 2026년 9월 9일에 지원이 종료되었으며, API 서버는 클라이언트 라이브러리 버전에 관계없이developer-token헤더를 무시합니다 (향후 Google Ads API의 메이저 버전에서 거부될 때까지). 이전 클라이언트 라이브러리 버전에서는 여전히 로컬 클라이언트 측 유효성 검사에 비어 있지 않은 값이 필요합니다. 버전별 세부정보는 각 라이브러리의 구성 가이드를 참고하세요.GOOGLE_ADS_LOGIN_CUSTOMER_ID: 요청에 사용할 승인된 고객의 고객 ID입니다 (하이픈 제외,-).GOOGLE_ADS_LINKED_CUSTOMER_ID: 이 헤더는 Google Ads UI의 연결된 계정을 통해 권한이 부여된 경우 엔티티의 리소스를 업데이트하는 메서드에만 필요합니다 (Google Ads API의AccountLink리소스). 이 값을 지정된 고객 ID의 리소스를 업데이트하는 데이터 제공업체의 고객 ID로 설정합니다. 하이픈 (-) 없이 설정해야 합니다. 연결된 계정에 대해 자세히 알아보려면 고객센터를 방문하세요.
환경 변수는 일반적으로 $HOME 디렉터리에 있는 .bashrc 또는 .bash_profile 파일과 같은 bash 구성 파일에 정의됩니다. 명령줄을 사용하여 정의할 수도 있습니다.
터미널을 사용하여 .bashrc 파일을 통해 환경 변수를 정의하는 기본 단계는 다음과 같습니다.
# Append the line "export GOOGLE_ADS_CLIENT_ID=1234567890" to
# the bottom of your .bashrc file.
echo "export GOOGLE_ADS_CLIENT_ID=1234567890" >> ~/.bashrc
# Update your bash environment to use the most recently updated
# version of your .bashrc file.
source ~/.bashrc
명령줄에서 직접 터미널 인스턴스에 환경 변수를 설정할 수도 있습니다.
export GOOGLE_ADS_CLIENT_ID=1234567890
또 다른 방법은 환경 변수를 사용하는 명령어를 호출할 때 환경 변수를 설정하는 것입니다.
GOOGLE_ADS_CLIENT_ID=1234567890 php /path/to/script/that/uses/envvar.php
항목 가져오기
GoogleAdsService.SearchStream는 일반적으로 항목을 가져오는 데 사용되며 결과는 행 스트림으로 반환됩니다. 또는 GoogleAdsService.Search를 사용하여 신뢰할 수 없는 인터넷 연결을 통해 엔티티를 가져올 수 있습니다. GoogleAdsService.Search는 페이지당 10,000개 행의 고정 페이지 크기로 결과를 반환합니다.
클라이언트 라이브러리는 결과를 반복할 때 자동으로 페이지로 나누기를 구현하므로 모든 결과를 한 번에 순차적으로 다운로드하고 처리할 수 있습니다.
자바
private void runExample(GoogleAdsClient googleAdsClient, long customerId) { try (GoogleAdsServiceClient googleAdsServiceClient = googleAdsClient.getLatestVersion().createGoogleAdsServiceClient()) { String query = "SELECT campaign.id, campaign.name FROM campaign ORDER BY campaign.id"; // Constructs the SearchGoogleAdsStreamRequest. SearchGoogleAdsStreamRequest request = SearchGoogleAdsStreamRequest.newBuilder() .setCustomerId(Long.toString(customerId)) .setQuery(query) .build(); // Creates and issues a search Google Ads stream request that will retrieve all campaigns. ServerStream<SearchGoogleAdsStreamResponse> stream = googleAdsServiceClient.searchStreamCallable().call(request); // Iterates through and prints all of the results in the stream response. for (SearchGoogleAdsStreamResponse response : stream) { for (GoogleAdsRow googleAdsRow : response.getResultsList()) { System.out.printf( "Campaign with ID %d and name '%s' was found.%n", googleAdsRow.getCampaign().getId(), googleAdsRow.getCampaign().getName()); } } } }
C#
public void Run(GoogleAdsClient client, long customerId) { // Get the GoogleAdsService. GoogleAdsServiceClient googleAdsService = client.GetService( Services.V25.GoogleAdsService); // Create a query that will retrieve all campaigns. string query = @"SELECT campaign.id, campaign.name, campaign.network_settings.target_content_network FROM campaign ORDER BY campaign.id"; try { // Issue a search request. googleAdsService.SearchStream(customerId.ToString(), query, delegate (SearchGoogleAdsStreamResponse resp) { foreach (GoogleAdsRow googleAdsRow in resp.Results) { Console.WriteLine("Campaign with ID {0} and name '{1}' was found.", googleAdsRow.Campaign.Id, googleAdsRow.Campaign.Name); } } ); } catch (GoogleAdsException e) { Console.WriteLine("Failure:"); Console.WriteLine($"Message: {e.Message}"); Console.WriteLine($"Failure: {e.Failure}"); Console.WriteLine($"Request ID: {e.RequestId}"); throw; } }
PHP
public static function runExample(GoogleAdsClient $googleAdsClient, int $customerId) { $googleAdsServiceClient = $googleAdsClient->getGoogleAdsServiceClient(); // Creates a query that retrieves all campaigns. $query = 'SELECT campaign.id, campaign.name FROM campaign ORDER BY campaign.id'; // Issues a search stream request. /** @var GoogleAdsServerStreamDecorator $stream */ $stream = $googleAdsServiceClient->searchStream( SearchGoogleAdsStreamRequest::build($customerId, $query) ); // Iterates over all rows in all messages and prints the requested field values for // the campaign in each row. foreach ($stream->iterateAllElements() as $googleAdsRow) { /** @var GoogleAdsRow $googleAdsRow */ printf( "Campaign with ID %d and name '%s' was found.%s", $googleAdsRow->getCampaign()->getId(), $googleAdsRow->getCampaign()->getName(), PHP_EOL ); } }
Python
def main(client: GoogleAdsClient, customer_id: str) -> None: ga_service: GoogleAdsServiceClient = client.get_service("GoogleAdsService") query: str = """ SELECT campaign.id, campaign.name FROM campaign ORDER BY campaign.id""" # Issues a search request using streaming. stream: Iterator[SearchGoogleAdsStreamResponse] = ga_service.search_stream( customer_id=customer_id, query=query ) for batch in stream: rows: List[GoogleAdsRow] = batch.results for row in rows: print( f"Campaign with ID {row.campaign.id} and name " f'"{row.campaign.name}" was found.' )
Ruby
def get_campaigns(customer_id) # GoogleAdsClient will read a config file from # ENV['HOME']/google_ads_config.rb when called without parameters client = Google::Ads::GoogleAds::GoogleAdsClient.new responses = client.service.google_ads.search_stream( customer_id: customer_id, query: 'SELECT campaign.id, campaign.name FROM campaign ORDER BY campaign.id', ) responses.each do |response| response.results.each do |row| puts "Campaign with ID #{row.campaign.id} and name '#{row.campaign.name}' was found." end end end
Perl
sub get_campaigns { my ($api_client, $customer_id) = @_; # Create a search Google Ads stream request that will retrieve all campaigns. my $search_stream_request = Google::Ads::GoogleAds::V25::Services::GoogleAdsService::SearchGoogleAdsStreamRequest ->new({ customerId => $customer_id, query => "SELECT campaign.id, campaign.name FROM campaign ORDER BY campaign.id" }); # Get the GoogleAdsService. my $google_ads_service = $api_client->GoogleAdsService(); my $search_stream_handler = Google::Ads::GoogleAds::Utils::SearchStreamHandler->new({ service => $google_ads_service, request => $search_stream_request }); # Issue a search request and process the stream response to print the requested # field values for the campaign in each row. $search_stream_handler->process_contents( sub { my $google_ads_row = shift; printf "Campaign with ID %d and name '%s' was found.\n", $google_ads_row->{campaign}{id}, $google_ads_row->{campaign}{name}; }); return 1; }
curl
코드 예시
Google Ads API의 일반적인 함수의 코드 예시를 확인하세요.