클라이언트 설치 및 구성

Google API 클라이언트 라이브러리를 Bid Manager API와 함께 사용하는 것이 좋으므로 HTTP 요청과 응답을 수동으로 처리할 필요가 없습니다. Google API 클라이언트 라이브러리는 더 나은 언어 통합, 향상된 보안, 사용자 승인이 필요한 호출에 대한 지원이 제공됩니다.

Bid Manager API는 HTTP 및 JSON에 기반합니다. 요청을 처리하려는 경우 모든 표준 HTTP 클라이언트를 사용할 수 있습니다

클라이언트 라이브러리 설치

Google은 다양한 환경에서 Bid Manager API를 지원하는 클라이언트 라이브러리를 제공합니다. 사용할 수 있습니다. 클라이언트 라이브러리의 전체 목록은 샘플 및 라이브러리 탭을 선택합니다.

Bid Manager API 개발자 가이드에서는 다음 세 가지에 대한 코드 스니펫을 제공합니다. 언어:

이러한 언어로 된 전체 통합 예는 Bid Manager API 예제를 참조하세요. GitHub 저장소에 있어야 합니다.

클라이언트 구성

OAuth 2.0 사용자 인증 정보설치된 클라이언트 사용 라이브러리를 사용하면 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 java.io.Reader;
    import java.nio.file.Files;
    import java.nio.file.Paths;
    
  2. 클라이언트 보안 비밀 파일을 로드하고 승인 사용자 인증 정보를 생성합니다.

    이 단계를 처음 수행하면 승인을 수락하라는 메시지가 표시됩니다. 메시지가 표시됩니다. 수락하기 전에 디스플레이 및 동영상 360 앱이 승인됩니다. 현재 로그인된 계정을 대신하여 데이터에 액세스할 수 있습니다

    // 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();
    

Python

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

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

    이 단계를 처음 수행하면 승인을 수락하라는 메시지가 표시됩니다. 메시지가 표시됩니다. 수락하기 전에 디스플레이 및 동영상 360 앱이 승인됩니다. 현재 로그인된 계정을 대신하여 데이터에 액세스할 수 있습니다

    # 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)
    

PHP

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

php -S localhost:8000 -t ./

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

    선호되는 방법은 Composer를 사용하는 것입니다. <ph type="x-smartling-placeholder">

    composer require google/apiclient:^2.12.1
    
    </ph>

    설치가 완료되면 자동 로더를 포함해야 합니다.

    require_once '/path/to/your-project/vendor/autoload.php';
    

  2. Google_Client 객체를 만듭니다.

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

    이 단계를 처음 수행하면 승인을 수락하라는 메시지가 표시됩니다. 메시지가 표시됩니다. 수락하기 전에 디스플레이 및 동영상 360 앱이 승인됩니다. 현재 로그인된 계정을 대신하여 데이터에 액세스할 수 있습니다

    // 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. 디스플레이 및 Video 360 API 서비스

    $service = new Google_Service_DoubleClickBidManager($client);