시작하기

Campaign Manager 360 API를 사용하면 Campaign Manager 360 계정의 정보에 프로그래매틱 방식으로 액세스할 수 있습니다. Campaign Manager 360 및 보고서 작성 도구 웹 서비스에서와 마찬가지로 캠페인과 보고서를 관리하고 만드는 데 사용됩니다.

이 가이드에서는 Campaign Manager 360 API를 시작하는 방법을 설명합니다.

기본 요건

Campaign Manager 360 API를 사용하기 전에 충족해야 하는 몇 가지 전제 조건이 있습니다.

  1. Campaign Manager 360 계정이 있어야 합니다. 가입 정보는 광고주/대행사를 참고하세요.

  2. Campaign Manager 360 계정에서 API 액세스가 사용 설정되어 있어야 합니다. 대부분의 계정은 기본적으로 이 기능이 사용 설정되어 있습니다. 확실하지 않으면 계정 담당자 또는 Campaign Manager 360 지원팀에 문의하세요.

  3. 이 계정에 액세스할 수 있는 사용자 프로필이 있어야 합니다. Campaign Manager 360 계정 관리자에게 이 계정과 연결된 사용자 프로필을 만들어 달라고 요청하세요.

  4. Campaign Manager 360 UI에서 사용자 프로필 권한을 확인하세요. API에서 사용자 프로필이 액세스할 수 있는 항목을 제어합니다. 별도의 API 권한은 없습니다.

프로젝트 만들기

Campaign Manager 360 API를 사용하려면 먼저 Google API 콘솔에서 프로젝트를 만들거나 선택하고 API를 사용 설정해야 합니다. 이 링크를 사용하면 절차를 안내받고 Campaign Manager 360 API가 자동으로 활성화됩니다.

사용자 인증 정보 만들기

Campaign Manager 360 API에 대한 모든 요청은 승인되어야 합니다. 승인에 관한 간략한 개요는 애플리케이션 승인 및 Google에 식별을 참조하세요.

다음 안내는 설치된 애플리케이션 흐름에서 사용할 OAuth 2.0 클라이언트 ID를 만드는 프로세스를 안내합니다. 서비스 계정 흐름에 사용할 사용자 인증 정보를 생성하는 방법에 대한 안내는 서비스 계정 가이드를 참조하세요.

  1. Google API 콘솔 프로젝트 구성 단계를 따릅니다.

  2. API 콘솔에서 사용자 인증 정보 페이지를 엽니다.
  3. 사용자 인증 정보 만들기 > OAuth 클라이언트 ID를 클릭합니다.

    1. 이전에 이 프로젝트에 OAuth 동의 화면을 구성하지 않았으면 지금 구성하라는 메시지가 표시됩니다. 동의 화면 구성을 클릭합니다.

    2. 사용자 유형을 선택하고 만들기를 클릭합니다.

    3. 초기 양식을 작성합니다. 필요한 경우 나중에 수정할 수 있습니다. 완료되면 저장을 클릭합니다.

    4. 사용자 인증 정보 > 사용자 인증 정보 만들기 > OAuth 클라이언트 ID로 돌아가서 계속 진행합니다.

  4. 애플리케이션 유형으로 데스크톱 앱을 선택하고 이름을 지정한 다음 만들기를 클릭합니다.

완료되면 OAuth 2.0 클라이언트 ID와 클라이언트 비밀번호가 표시되며, 이 정보는 JSON 형식으로 다운로드하여 나중에 사용할 수 있도록 저장할 수 있습니다.

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

Campaign Manager 360 API는 HTTP 및 JSON에 기반하므로 모든 표준 HTTP 클라이언트가 여기에 요청을 보내고 응답을 파싱할 수 있습니다.

그러나 Google API 클라이언트 라이브러리는 더 나은 언어 통합, 향상된 보안, 승인된 요청 지원을 제공합니다. 이 클라이언트 라이브러리는 다양한 프로그래밍 언어로 제공되므로 HTTP 요청을 직접 설정하고 응답을 파싱하지 않아도 됩니다.

시작하려면 개발에 사용 중인 프로그래밍 언어를 선택하세요.

C#

최신 .NET용 Campaign Manager 360 API 클라이언트 라이브러리를 설치합니다. NuGet을 사용하여 설치를 관리하는 것이 좋습니다.

NuGet 패키지 관리자 콘솔을 열고 다음 명령어를 실행합니다.

Install-Package Google.Apis.Dfareporting.v3_4

자세히 알아보기

자바

최신 자바용 Campaign Manager 360 API 클라이언트 라이브러리를 설치합니다. Maven을 사용하여 설치를 관리하는 것이 좋습니다.

pom.xml 파일에 다음 종속 항목을 추가합니다.

<dependency>
  <groupId>com.google.apis</groupId>
  <artifactId>google-api-services-dfareporting</artifactId>
  <version>v4-rev20220611-1.32.1</version>
  <exclusions>
    <exclusion>
      <groupId>com.google.guava</groupId>
      <artifactId>guava-jdk5</artifactId>
    </exclusion>
  </exclusions>
</dependency>

자세히 알아보기

2,399필리핀

최신 PHP용 Campaign Manager 360 API 클라이언트 라이브러리를 설치합니다. Composer를 사용하여 설치를 관리하는 것이 좋습니다.

터미널을 열고 다음 명령어를 실행합니다.

composer require google/apiclient

이미 라이브러리를 설치했고 최신 버전으로 업데이트하려면 다음 단계를 따르세요.

composer update google/apiclient

시스템에 따라 명령어 앞에 sudo를 추가해야 할 수 있습니다.

자세히 알아보기

Python

최신 Python용 Campaign Manager 360 API 클라이언트 라이브러리를 설치합니다. pip를 사용하여 설치를 관리하는 것이 좋습니다.

터미널을 열고 다음 명령어를 실행합니다.

pip install --upgrade google-api-python-client

시스템에 따라 명령어 앞에 sudo를 추가해야 할 수 있습니다.

자세히 알아보기

Ruby

최신 Ruby용 Campaign Manager 360 API 클라이언트 라이브러리를 설치합니다. RubyGems를 사용하여 설치를 관리하는 것이 좋습니다.

터미널을 열고 다음 명령어를 실행합니다.

gem install google-api-client

이미 라이브러리를 설치했고 최신 버전으로 업데이트하려면 다음 단계를 따르세요.

gem update -y google-api-client

시스템에 따라 명령어 앞에 sudo를 추가해야 할 수 있습니다.

자세히 알아보기

지원되는 언어는 클라이언트 라이브러리 페이지에서 확인할 수 있습니다.

요청하기

OAuth 2.0 사용자 인증 정보가 생성되고 클라이언트 라이브러리가 설치되면 Campaign Manager 360 API를 사용할 준비가 된 것입니다. 아래의 빠른 시작에 따라 승인, 클라이언트 구성, 첫 번째 요청 방법을 알아보세요.

C#

  1. 클라이언트 보안 비밀 파일을 로드하고 승인 사용자 인증 정보를 생성합니다.

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

    // Load client secrets from the specified JSON file.
    GoogleClientSecrets clientSecrets;
    using(Stream json = new FileStream(pathToJsonFile, FileMode.Open, FileAccess.Read)) {
      clientSecrets = GoogleClientSecrets.Load(json);
    }
    
    // Create an asynchronous authorization task.
    //
    // Note: providing a data store allows auth credentials to be cached, so they survive multiple
    // runs of the application. This avoids prompting the user for authorization every time the
    // access token expires, by remembering the refresh token. The "user" value is used to
    // identify a specific set of credentials within the data store. You may provide different
    // values here to persist credentials for multiple users to the same data store.
    Task<UserCredential> authorizationTask = GoogleWebAuthorizationBroker.AuthorizeAsync(
        clientSecrets.Secrets,
        OAuthScopes,
        "user",
        CancellationToken.None,
        dataStore);
    
    // Authorize and persist credentials to the data store.
    UserCredential credential = authorizationTask.Result;
    
  2. 승인된 DFA 보고 클라이언트를 만듭니다.

    // Create a Dfareporting service object.
    //
    // Note: application name should be replaced with a value that identifies your application.
    service = new DfareportingService(
        new BaseClientService.Initializer {
          HttpClientInitializer = credential,
          ApplicationName = "C# installed app sample"
        }
    );
    
  3. 작업을 수행합니다.

    // Retrieve and print all user profiles for the current authorized user.
    UserProfileList profiles = service.UserProfiles.List().Execute();
    
    foreach (UserProfile profile in profiles.Items) {
      Console.WriteLine("Found user profile with ID {0} and name \"{1}\".",
          profile.ProfileId, profile.UserName);
    }
    

자바

  1. 클라이언트 보안 비밀 파일을 로드하고 승인 사용자 인증 정보를 생성합니다.

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

    // Load the client secrets JSON file.
    GoogleClientSecrets clientSecrets =
        GoogleClientSecrets.load(
            jsonFactory, Files.newBufferedReader(Paths.get(pathToClientSecretsFile), UTF_8));
    
    // Set up the authorization code flow.
    //
    // Note: providing a DataStoreFactory allows auth credentials to be cached, so they survive
    // multiple runs of the program. This avoids prompting the user for authorization every time the
    // access token expires, by remembering the refresh token.
    GoogleAuthorizationCodeFlow flow =
        new GoogleAuthorizationCodeFlow.Builder(
                httpTransport, jsonFactory, clientSecrets, OAUTH_SCOPES)
            .setDataStoreFactory(dataStoreFactory)
            .build();
    
    // Authorize and persist credentials to the data store.
    //
    // Note: the "user" value below is used to identify a specific set of credentials in the data
    // store. You may provide different values here to persist credentials for multiple users to
    // the same data store.
    Credential credential =
        new AuthorizationCodeInstalledApp(flow, new LocalServerReceiver()).authorize("user");
    
  2. 승인된 DFA 보고 클라이언트를 만듭니다.

    // Create a Dfareporting client instance.
    //
    // Note: application name below should be replaced with a value that identifies your
    // application. Suggested format is "MyCompany-ProductName/Version.MinorVersion".
    Dfareporting reporting =
        new Dfareporting.Builder(credential.getTransport(), credential.getJsonFactory(), credential)
            .setApplicationName("dfareporting-java-installed-app-sample")
            .build();
    
  3. 작업을 수행합니다.

    // Retrieve and print all user profiles for the current authorized user.
    UserProfileList profiles = reporting.userProfiles().list().execute();
    for (int i = 0; i < profiles.getItems().size(); i++) {
      System.out.printf("%d) %s%n", i + 1, profiles.getItems().get(i).getUserName());
    }
    

2,399필리핀

  1. 클라이언트 보안 비밀 파일을 로드하고 승인 사용자 인증 정보를 생성합니다.

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

    // Create a Google_Client instance.
    //
    // Note: application name should be replaced with a value that identifies
    // your application. Suggested format is "MyCompany-ProductName".
    $client = new Google_Client();
    $client->setAccessType('offline');
    $client->setApplicationName('PHP installed app sample');
    $client->setRedirectUri(self::OAUTH_REDIRECT_URI);
    $client->setScopes(self::$OAUTH_SCOPES);
    
    // Load the client secrets file.
    $client->setAuthConfig($pathToJsonFile);
    
    // Try to load cached credentials from the token store. Using a token store
    // allows auth credentials to be cached, so they survive multiple runs of
    // the application. This avoids prompting the user for authorization every
    // time the access token expires, by remembering the refresh token.
    if (file_exists($tokenStore) && filesize($tokenStore) > 0) {
        $client->setAccessToken(file_get_contents($tokenStore));
    } else {
        // If no cached credentials were found, authorize and persist
        // credentials to the token store.
        print 'Open this URL in your browser and authorize the application.';
        printf("\n\n%s\n\n", $client->createAuthUrl());
        print 'Enter the authorization code: ';
        $code = trim(fgets(STDIN));
        $client->authenticate($code);
    
        file_put_contents($tokenStore, json_encode($client->getAccessToken()));
    }
    
  2. 승인된 DFA 보고 클라이언트를 만듭니다.

    // Create a Dfareporting service object.
    $service = new Google_Service_Dfareporting($client);
    
  3. 작업을 수행합니다.

    // Retrieve and print all user profiles for the current authorized user.
    $result = $service->userProfiles->listUserProfiles();
    foreach ($result['items'] as $userProfile) {
        printf(
            "User profile \"%s\" (ID: %d) found for account %d.\n",
            $userProfile->getUserName(),
            $userProfile->getProfileId(),
            $userProfile->getAccountId()
        );
    }
    

Python

  1. 클라이언트 보안 비밀 파일을 로드하고 승인 사용자 인증 정보를 생성합니다.

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

    # Set up a Flow object to be used if we need to authenticate.
    flow = client.flow_from_clientsecrets(
        path_to_client_secrets_file, scope=OAUTH_SCOPES)
    
    # Check whether credentials exist in the credential store. Using a credential
    # store allows auth credentials to be cached, so they survive multiple runs
    # of the application. This avoids prompting the user for authorization every
    # time the access token expires, by remembering the refresh token.
    storage = Storage(CREDENTIAL_STORE_FILE)
    credentials = storage.get()
    
    # If no credentials were found, go through the authorization process and
    # persist credentials to the credential store.
    if credentials is None or credentials.invalid:
      credentials = tools.run_flow(flow, storage,
                                   tools.argparser.parse_known_args()[0])
    
    # Use the credentials to authorize an httplib2.Http instance.
    http = credentials.authorize(httplib2.Http())
    
  2. 승인된 DFA 보고 클라이언트를 만듭니다.

    # Construct a service object via the discovery service.
    service = discovery.build('dfareporting', 'v4', http=http)
    
  3. 작업을 수행합니다.

    # Construct the request.
    request = service.userProfiles().list()
    
    # Execute request and print response.
    response = request.execute()
    
    for profile in response['items']:
      print('Found user profile with ID %s and user name "%s".' %
            (profile['profileId'], profile['userName']))
    

Ruby

  1. 클라이언트 보안 비밀 파일을 로드하고 승인 사용자 인증 정보를 생성합니다.

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

    # Load client ID from the specified file.
    client_id = Google::Auth::ClientId.from_file(path_to_json_file)
    
    # Set up the user authorizer.
    #
    # Note: providing a token store allows auth credentials to be cached, so they
    # survive multiple runs of the application. This avoids prompting the user for
    # authorization every time the access token expires, by remembering the
    # refresh token.
    authorizer = Google::Auth::UserAuthorizer.new(
      client_id, [API_NAMESPACE::AUTH_DFAREPORTING], token_store
    )
    
    # Authorize and persist credentials to the data store.
    #
    # Note: the 'user' value below is used to identify a specific set of
    # credentials in the token store. You may provide different values here to
    # persist credentials for multiple users to the same token store.
    authorization = authorizer.get_credentials('user')
    if authorization.nil?
      puts format(
        "Open this URL in your browser and authorize the application.\n\n%s" \
        "\n\nEnter the authorization code:",
        authorizer.get_authorization_url(base_url: OAUTH_REDIRECT_URI)
      )
      code = STDIN.gets.chomp
      authorization = authorizer.get_and_store_credentials_from_code(
        base_url: OAUTH_REDIRECT_URI, code: code, user_id: 'user'
      )
    end
    
  2. 승인된 DFA 보고 클라이언트를 만듭니다.

    # Create a Dfareporting service object.
    #
    # Note: application name should be replaced with a value that identifies
    # your application. Suggested format is "MyCompany-ProductName".
    service = API_NAMESPACE::DfareportingService.new
    service.authorization = authorization
    service.client_options.application_name = 'Ruby installed app sample'
    service.client_options.application_version = '1.0.0'
    
  3. 작업을 수행합니다.

    // Retrieve and print all user profiles for the current authorized user.
    UserProfileList profiles = service.UserProfiles.List().Execute();
    
    foreach (UserProfile profile in profiles.Items) {
      Console.WriteLine("Found user profile with ID {0} and name \"{1}\".",
          profile.ProfileId, profile.UserName);
    }
    

자세히 알아보기

API가 제공하는 모든 서비스에 대해 알아보려면 API 참조를 확인하세요. 모든 메서드 세부정보 페이지에는 브라우저에서 직접 테스트 요청을 수행하는 데 사용할 수 있는 API 탐색기가 삽입되어 있습니다.

고급 주제를 다루는 다른 가이드를 검토하고 일반적인 작업에 대한 엔드 투 엔드 예를 제공합니다.

코드 작성을 시작할 준비가 되면 Google의 광범위한 코드 샘플 모음을 살펴보세요. 필요에 따라 수정하고 확장할 수 있습니다.