Bid Manager API v1.1은 사용이 중단되었습니다. 지원 중단 버전을 요청하면 오류가 반환되거나 불완전한 데이터가 반환될 수 있습니다.

Bid Manager API v2를 사용해야 합니다. v1.1에서 v2로 이전하는 단계는 이전 가이드를 참고하세요.

API 시작하기

이 문서에서는 Google Bid Manager API를 사용하는 앱을 작성하는 방법을 설명합니다. API를 사용하면 쿼리를 관리하고 보고서 메타데이터를 가져올 수 있습니다.

Bid Manager API v2는 사용 가능한 최신 버전입니다.

1. 시작하기 전에

Google Display & Video 360 개념에 익숙하지 않은 경우 Display & Video 360 고객센터를 읽고 UI를 실험해 보세요.

2. 인증 준비

Bid Manager API를 사용하려면 먼저 설정 도구를 사용하여 Google API 콘솔에서 프로젝트를 만들고 API를 사용 설정하며 사용자 인증 정보를 만드는 과정을 진행합니다.

아직 OAuth 2.0 사용자 인증 정보를 만들지 않았다면 사용자 인증 정보 만들기 > OAuth 클라이언트 ID를 클릭합니다. 사용자 인증 정보를 만들면 사용자 인증 정보 페이지에 클라이언트 ID가 표시됩니다. 클라이언트 비밀번호, 리디렉션 URI, 자바스크립트 원본 주소, 이메일 주소 등 자세한 내용을 보려면 클라이언트 ID를 클릭하세요.

자세한 내용은 요청 승인을 참조하세요.

3. Bid Manager API 호출

아래 탭에서는 다양한 언어로 코딩하는 빠른 시작을 제공합니다. 유사한 샘플 코드는 Bid Manager API 예시 저장소에서도 확인할 수 있습니다.

자바

  1. 필요한 라이브러리를 가져옵니다.

    import static java.nio.charset.StandardCharsets.UTF_8;
    import com.google.api.client.auth.oauth2.Credential;
    import com.google.api.client.extensions.java6.auth.oauth2.AuthorizationCodeInstalledApp;
    import com.google.api.client.extensions.jetty.auth.oauth2.LocalServerReceiver;
    import com.google.api.client.googleapis.auth.oauth2.GoogleAuthorizationCodeFlow;
    import com.google.api.client.googleapis.auth.oauth2.GoogleClientSecrets;
    import com.google.api.client.googleapis.util.Utils;
    import com.google.api.services.doubleclickbidmanager.DoubleClickBidManager;
    import com.google.api.services.doubleclickbidmanager.model.ListQueriesResponse;
    import com.google.api.services.doubleclickbidmanager.model.Query;
    import java.io.Reader;
    import java.nio.file.Files;
    import java.nio.file.Paths;
    
  2. 클라이언트 보안 비밀 파일을 로드하고 승인 사용자 인증 정보를 생성합니다.

    이 단계를 처음 수행하면 브라우저에서 승인 메시지를 수락하라는 메시지가 표시됩니다. 동의하기 전에 Display & Video 360에 액세스할 수 있는 Google 계정으로 로그인했는지 확인하세요. 앱은 현재 로그인한 계정을 대신하여 데이터에 액세스할 수 있는 권한이 부여됩니다.

    // Read client secrets file.
    GoogleClientSecrets clientSecrets;
    try (Reader reader = Files.newBufferedReader(Paths.get(path-to-client-secrets-file), UTF_8)) {
      clientSecrets = GoogleClientSecrets.load(Utils.getDefaultJsonFactory(), reader);
    }
    
    // Generate authorization credentials.
    // Set up the authorization code flow.
    GoogleAuthorizationCodeFlow flow =
        new GoogleAuthorizationCodeFlow.Builder(
            Utils.getDefaultTransport(),
            Utils.getDefaultJsonFactory(),
            clientSecrets,
            oauth-scopes)
        .build();
    
    Credential credential =
        new AuthorizationCodeInstalledApp(flow, new LocalServerReceiver()).authorize("user");
    
  3. 승인된 API 클라이언트를 만듭니다.

    // Create authorized API client.
    DoubleClickBidManager service =
        new DoubleClickBidManager.Builder(credential.getTransport(), credential.getJsonFactory(), credential)
            .setApplicationName("bidmanager-java-installed-app-sample")
            .build();
    
  4. 작업을 수행합니다.

    // Perform an operation.
    // Call the API, getting a list of 10 queries.
    ListQueriesResponse queriesResponse = service.queries().list().setPageSize(10).execute();
    
    // Print them out.
    System.out.println("Id\t\tName");
    if (queriesResponse.getQueries().size() > 0) {
      for (int i = 0; i < queriesResponse.getQueries().size(); i++) {
        Query currentQuery = queriesResponse.getQueries().get(i);
        System.out.printf(
            "%s\t%s%n",
            currentQuery.getQueryId(),
            currentQuery.getMetadata().getTitle());
      }
    } else {
      System.out.println("No queries exist.");
    }
    

자바에서 Bid Manager API를 사용하는 방법에 대한 자세한 내용은 Bid Manager API 예시README 파일을 참조하세요.

Python

  1. 필요한 라이브러리를 가져옵니다.

    from google_auth_oauthlib.flow import InstalledAppFlow
    from googleapiclient import discovery
    
  2. 클라이언트 보안 비밀 파일을 로드하고 승인 사용자 인증 정보를 생성합니다.

    이 단계를 처음 수행하면 브라우저에서 승인 메시지를 수락하라는 메시지가 표시됩니다. 동의하기 전에 Display & Video 360에 액세스할 수 있는 Google 계정으로 로그인했는지 확인하세요. 앱은 현재 로그인한 계정을 대신하여 데이터에 액세스할 수 있는 권한이 부여됩니다.

    # Set up a flow object to create the credentials using the
    # client secrets file and OAuth scopes.
    credentials = InstalledAppFlow.from_client_secrets_file(
        path-to-client-secrets-file, oauth-scopes).run_local_server()
    
  3. 승인된 API 클라이언트를 만듭니다.

    # Build the discovery document URL.
    discovery_url = f'https://doubleclickbidmanager.googleapis.com/$discovery/rest?version=v2'
    
    # Build the API service.
    service = discovery.build(
        'doubleclickbidmanager',
        'v2',
        discoveryServiceUrl=discovery_url,
        credentials=credentials)
    
  4. 작업을 수행합니다.

    # Build and execute queries.listqueries request.
    response = service.queries().list(pageSize='10').execute()
    
    # Print queries out.
    if 'queries' in response:
      print('Id\t\tName')
      for query in response['queries']:
        print('%s\t%s' % (query['queryId'], query['metadata']['title']))
    else:
      print('No queries exist.')
    

Python에서 Bid Manager API를 사용하는 방법에 대한 자세한 내용은 Bid Manager API 예시README 파일을 참조하세요.

PHP

이 샘플에서는 PHP가 기본 제공되는 웹 서버를 실행 중이고 관련 웹페이지로 리디렉션되도록 사용자 인증 정보를 구성했다고 가정합니다. 예를 들어 index.php 파일에서 이 코드는 인증 후 http://localhost:8000로 리디렉션하도록 구성된 다음 명령어 및 사용자 인증 정보를 사용하여 실행할 수 있습니다.

php -S localhost:8000 -t ./

  1. Google API PHP 클라이언트를 다운로드하여 설치합니다.

    선호되는 메서드는 Composer를 사용하는 것입니다.

    composer require google/apiclient:^2.12.1
    

    설치되면 자동 로더

    require_once '/path/to/your-project/vendor/autoload.php';
    
    를 포함해야 합니다.

  2. Google_Client 객체를 만듭니다.

    $client = new Google_Client();
    
  3. 클라이언트를 설정하고 필요한 경우 인증 URL로 리디렉션한 다음 액세스 토큰을 가져옵니다.

    이 단계를 처음 수행하면 브라우저에서 승인 메시지를 수락하라는 메시지가 표시됩니다. 동의하기 전에 Display & Video 360에 액세스할 수 있는 Google 계정으로 로그인했는지 확인하세요. 앱은 현재 로그인한 계정을 대신하여 데이터에 액세스할 수 있는 권한이 부여됩니다.

    // Set up the client.
    $client->setApplicationName('DBM API PHP Samples');
    $client->addScope(oauth-scope);
    $client->setAccessType('offline');
    $client->setAuthConfigFile(path-to-client-secrets-file);
    
    // If the code is passed, authenticate. If not, redirect to authentication page.
    if (isset($_GET['code'])) {
      $client->authenticate($_GET['code']);
    } else {
      $authUrl = $client->createAuthUrl();
      header('Location: ' . $authUrl);
    }
    
    // Exchange authorization code for an access token.
    $accessToken = $client->getAccessToken();
    $client->setAccessToken($accessToken);
    
  4. Display &Video 360 API 서비스를 위한 클라이언트 구성

    $service = new Google_Service_DoubleClickBidManager($client);
    
  5. 작업을 수행합니다.

    // Configure params for the Queries.listqueries request.
    $optParams = array('pageSize' => 10);
    
    // Execute the request.
    $result = $service->queries->listQueries($optParams);
    
    // Print the retrieved queries.
    if (!empty($result->getQueries())) {
      print('<pre><p>Id Name</p>');
      foreach ($result->getQueries() as $query) {
        printf('<p>%s %s</p>', $query->queryId, $query->metadata->title);
      }
      print('</pre>');
    } else {
      print '<p>No queries exist.</p>';
    }
    

Bid Manager API를 PHP와 함께 사용하는 방법에 대한 자세한 내용은 Bid Manager API 예시README 파일을 참조하세요.

4. 다음 단계

이제 클라이언트 라이브러리가 실행되고 있으므로 참조 문서를 살펴보고 구현 빌드를 시작하세요.

예약 보고서 활용보고 권장사항에 대한 추가 가이드도 제공됩니다.