Mulai

Campaign Manager 360 API memberikan akses terprogram ke informasi dari Akun Campaign Manager 360. Sistem ini digunakan untuk mengelola dan membuat kampanye dan laporan, seperti yang Anda lakukan melalui layanan web Campaign Manager 360 dan Pembuat Laporan.

Panduan ini menjelaskan cara memulai Campaign Manager 360 API.

Prasyarat

Sebelum menggunakan Campaign Manager 360 API, ada beberapa langkah prasyarat yang perlu Anda memenuhi:

  1. Anda harus memiliki akun Campaign Manager 360. Lihat Pengiklan/Agensi untuk informasi pendaftaran.

  2. Akses API Campaign Manager 360 Anda harus diaktifkan. Paling sering akun mengaktifkannya secara {i>default<i}; jika tidak yakin, hubungi perwakilan akun Anda atau dukungan Campaign Manager 360 Google Workspace untuk mendapatkan bantuan.

  3. Anda harus memiliki profil pengguna dengan akses ke akun ini. Minta Administrator akun Campaign Manager 360 membuat profil pengguna yang terkait dengan akun ini.

  4. Periksa izin profil pengguna di UI Campaign Manager 360. Kontrol ini data apa saja yang dapat diakses oleh profil pengguna dari API. Tidak ada API yang terpisah izin akses.

Membuat project

Untuk mulai menggunakan Campaign Manager 360 API, Anda harus membuat atau pilih project di Konsol API Google dan aktifkan API. Dengan menggunakan akan memandu Anda melalui proses dan mengaktifkan Campaign Manager 360 API secara otomatis.

Membuat kredensial

Semua permintaan yang Anda buat ke Campaign Manager 360 API harus diizinkan. Untuk rangkuman ikhtisar otorisasi, baca tentang cara mengotorisasi dan mengidentifikasi aplikasi ke Google.

Petunjuk berikut akan memandu Anda melalui proses pembuatan OAuth 2.0 untuk digunakan dengan aplikasi yang terpasang alur. Untuk petunjuk tentang cara membuat kredensial untuk digunakan dengan alur akun layanan, lihat Akun Layanan kami.

  1. Ikuti langkah-langkah untuk mengonfigurasi project Konsol API Google.

  2. Buka halaman Credentials di Konsol API.
  3. Klik BUAT KREDENSIAL > Client ID OAuth yang baru.

    1. Jika Anda belum mengonfigurasi layar izin OAuth untuk project ini sebelumnya, Anda akan diarahkan untuk melakukannya sekarang. Klik KONFIGURASI PERSETUJUAN LAYAR.

    2. Pilih jenis pengguna, lalu klik CREATE.

    3. Isi formulir awal. Anda dapat mengeditnya nanti jika perlu. Klik Simpan jika sudah selesai.

    4. Kembali ke Credentials > BUAT KREDENSIAL > Client ID OAuth untuk melanjutkan.

  4. Pilih Aplikasi desktop sebagai jenis aplikasi, beri nama, lalu klik Buat.

Setelah selesai, Anda akan melihat client ID dan client ID OAuth 2.0 rahasia, yang dapat diunduh dalam format JSON dan disimpan untuk digunakan nanti.

Menginstal library klien

Campaign Manager 360 API dibuat di HTTP dan JSON, sehingga semua klien HTTP standar dapat mengirim terhadapnya dan menguraikan responsnya.

Namun, library klien Google API menyediakan integrasi bahasa yang lebih baik, peningkatan keamanan, dan dukungan untuk membuat permintaan yang diotorisasi. Klien {i>library<i} tersedia dalam sejumlah bahasa pemrograman; dengan menggunakannya dapat menghindari kebutuhan untuk mengatur permintaan HTTP secara manual dan mengurai respons.

Untuk memulai, pilih bahasa pemrograman yang Anda gunakan untuk pengembangan produk.

C#

Instal library klien Campaign Manager 360 API terbaru untuk .NET. Menggunakan Sebaiknya gunakan NuGet untuk mengelola penginstalan Anda.

Buka Konsol Pengelola Paket NuGet dan jalankan perintah berikut:

Install-Package Google.Apis.Dfareporting.v3_4

Pelajari Lebih Lanjut

Java

Instal library klien Campaign Manager 360 API terbaru untuk Java. Menggunakan Maven untuk mengelola penginstalan sangat disarankan.

Tambahkan dependensi berikut ke file pom.xml Anda:

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

Pelajari Lebih Lanjut

PHP

Instal library klien Campaign Manager 360 API terbaru untuk PHP. Menggunakan Sebaiknya gunakan Composer untuk mengelola penginstalan.

Buka terminal dan jalankan perintah berikut:

composer require google/apiclient

Jika Anda sudah menginstal {i>library<i} dan hanya ingin memperbarui ke versi terbaru:

composer update google/apiclient

Tergantung pada sistemnya, Anda mungkin perlu mengawali perintah ini dengan sudo.

Pelajari Lebih Lanjut

Python

Instal library klien Campaign Manager 360 API terbaru untuk Python. Menggunakan pip untuk mengelola penginstalan sangat direkomendasikan.

Buka terminal dan jalankan perintah berikut:

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

Tergantung pada sistemnya, Anda mungkin perlu mengawali perintah ini dengan sudo.

Pelajari Lebih Lanjut

Ruby

Instal library klien Campaign Manager 360 API terbaru untuk Ruby. Menggunakan RubyGems untuk mengelola penginstalan sangat disarankan.

Buka terminal dan jalankan perintah berikut:

gem install google-api-client

Jika Anda sudah menginstal {i>library<i} dan hanya ingin memperbarui ke versi terbaru:

gem update -y google-api-client

Tergantung pada sistemnya, Anda mungkin perlu mengawali perintah ini dengan sudo.

Pelajari Lebih Lanjut

Bahasa yang didukung lainnya dapat ditemukan di halaman Client Library.

Buat permintaan

Dengan kredensial OAuth 2.0 yang dibuat dan library klien diinstal, Anda siap untuk mulai menggunakan Campaign Manager 360 API. Pelajari caranya untuk mengotorisasi, mengonfigurasikan klien, dan membuat permintaan pertama dengan mengikuti panduan memulai di bawah ini.

C#

  1. Muat file rahasia klien dan buat kredensial otorisasi.

    Saat pertama kali melakukan langkah ini, Anda akan diminta untuk menyetujui permintaan otorisasi di browser. Sebelum menyetujui, pastikan Anda login dengan Akun Google yang memiliki akses ke Campaign Manager 360. Aplikasi Anda akan diberi otorisasi untuk mengakses data atas nama akun mana pun yang saat ini login.

    // 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. Buat klien Dfareporting resmi.

    // 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. Menjalankan operasi.

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

Java

  1. Muat file rahasia klien dan buat kredensial otorisasi.

    Saat pertama kali melakukan langkah ini, Anda akan diminta untuk menyetujui permintaan otorisasi di browser. Sebelum menyetujui, pastikan Anda login dengan Akun Google yang memiliki akses ke Campaign Manager 360. Aplikasi Anda akan diberi otorisasi untuk mengakses data atas nama akun mana pun yang saat ini login.

    // 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. Buat klien Dfareporting resmi.

    // 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. Menjalankan operasi.

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

PHP

  1. Muat file rahasia klien dan buat kredensial otorisasi.

    Saat pertama kali melakukan langkah ini, Anda akan diminta untuk menyetujui permintaan otorisasi di browser. Sebelum menyetujui, pastikan Anda login dengan Akun Google yang memiliki akses ke Campaign Manager 360. Aplikasi Anda akan diberi otorisasi untuk mengakses data atas nama akun mana pun yang saat ini login.

    // 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. Buat klien Dfareporting resmi.

    // Create a Dfareporting service object.
    $service = new Google_Service_Dfareporting($client);
    
  3. Menjalankan operasi.

    // 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. Muat file rahasia klien dan buat kredensial otorisasi.

    Saat pertama kali melakukan langkah ini, Anda akan diminta untuk menyetujui permintaan otorisasi di browser. Sebelum menyetujui, pastikan Anda login dengan Akun Google yang memiliki akses ke Campaign Manager 360. Aplikasi Anda akan diberi otorisasi untuk mengakses data atas nama akun mana pun yang saat ini login.

    # 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. Buat klien Dfareporting resmi.

    # Construct a service object via the discovery service.
    service = discovery.build('dfareporting', 'v4', http=http)
    
  3. Menjalankan operasi.

    # 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. Muat file rahasia klien dan buat kredensial otorisasi.

    Saat pertama kali melakukan langkah ini, Anda akan diminta untuk menyetujui permintaan otorisasi di browser. Sebelum menyetujui, pastikan Anda login dengan Akun Google yang memiliki akses ke Campaign Manager 360. Aplikasi Anda akan diberi otorisasi untuk mengakses data atas nama akun mana pun yang saat ini login.

    # 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. Buat klien Dfareporting resmi.

    # 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. Menjalankan operasi.

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

Pelajari lebih lanjut

Kunjungi Referensi API untuk mempelajari semua layanan yang disediakan yang ditawarkan oleh API. Setiap halaman detail metode memiliki API tersemat Penjelajah dapat Anda gunakan untuk membuat permintaan pengujian langsung dari browser.

Tinjau panduan kami yang lain yang mencakup topik lanjutan dan memberikan pemahaman menyeluruh untuk tugas-tugas umum.

Jika Anda sudah siap untuk mulai menulis kode, jangan ragu untuk mempelajari kumpulan contoh kode, yang dapat dimodifikasi dan diperluas agar sesuai dengan kebutuhan Anda.