เริ่มเลย

Campaign Manager 360 API ให้สิทธิ์แบบเป็นโปรแกรมในการเข้าถึงข้อมูลจาก บัญชี Campaign Manager 360 ซึ่งใช้ในการจัดการและสร้างแคมเปญและรายงาน เช่นเดียวกับที่คุณทําผ่านบริการเว็บ Campaign Manager 360 และเครื่องมือสร้างรายงาน

คู่มือนี้จะอธิบายวิธีเริ่มต้นใช้งาน Campaign Manager 360 API

ข้อกำหนดเบื้องต้น

คุณต้องทำตามขั้นตอนเบื้องต้น 2-3 ขั้นตอนต่อไปนี้ก่อนที่จะใช้ Campaign Manager 360 API ตรงกับ:

  1. คุณต้องมีบัญชี Campaign Manager 360 โปรดดู ผู้ลงโฆษณา/เอเจนซีสำหรับข้อมูลการลงชื่อสมัครใช้

  2. คุณต้องเปิดใช้บัญชี Campaign Manager 360 เพื่อเข้าถึง API พบบ่อยที่สุด ซึ่งบัญชีจะเปิดใช้ฟีเจอร์นี้โดยค่าเริ่มต้น หากคุณไม่แน่ใจ โปรดติดต่อ ตัวแทนฝ่ายดูแลลูกค้าหรือทีมสนับสนุนของ Campaign Manager 360 เพื่อขอความช่วยเหลือ

  3. คุณต้องมีโปรไฟล์ผู้ใช้ที่มีสิทธิ์เข้าถึงบัญชีนี้ มี ผู้ดูแลระบบบัญชี Campaign Manager 360 สร้างโปรไฟล์ผู้ใช้ที่เชื่อมโยงกับ บัญชีนี้

  4. ตรวจสอบสิทธิ์ของโปรไฟล์ผู้ใช้ใน UI ของ Campaign Manager 360 ตัวควบคุมเหล่านี้ ข้อมูลที่โปรไฟล์ผู้ใช้เข้าถึงได้จาก API ไม่มี API แยกต่างหาก สิทธิ์

สร้างโปรเจ็กต์

หากต้องการเริ่มต้นใช้งาน Campaign Manager 360 API ก่อนอื่นคุณต้องสร้าง หรือเลือกโปรเจ็กต์ในคอนโซล Google API และเปิดใช้ API การใช้ ลิงก์นี้จะแนะนำคุณตลอดกระบวนการและเปิดใช้งาน Campaign Manager 360 API โดยอัตโนมัติ

สร้างข้อมูลเข้าสู่ระบบ

คำขอทั้งหมดที่คุณส่งไปยัง Campaign Manager 360 API จะต้องได้รับสิทธิ์ ข้อมูลสรุป ภาพรวมของการให้สิทธิ์ อ่านเกี่ยวกับวิธี ให้สิทธิ์และระบุ กับ Google

วิธีการต่อไปนี้จะช่วยแนะนำกระบวนการสร้าง OAuth รหัสไคลเอ็นต์ 2.0 สำหรับใช้กับแอปพลิเคชันที่ติดตั้งไว้ สำหรับคำแนะนำในการสร้างข้อมูลเข้าสู่ระบบสำหรับการใช้งาน ในขั้นตอนของบัญชีบริการ ให้ดูที่บัญชีบริการ

  1. ทำตามขั้นตอนเพื่อกำหนดค่าโปรเจ็กต์คอนโซล Google API

  2. เปิดหน้าข้อมูลเข้าสู่ระบบในคอนโซล API
  3. คลิกสร้างข้อมูลรับรอง > รหัสไคลเอ็นต์ OAuth

    1. หากคุณไม่ได้กำหนดค่าหน้าจอคำยินยอม OAuth สำหรับโปรเจ็กต์นี้ ก่อนหน้านี้ ระบบจะนำคุณไปที่หน้าดำเนินการดังกล่าว คลิกกำหนดค่าความยินยอม SCREEN

    2. เลือกประเภทผู้ใช้แล้วคลิกสร้าง

    3. กรอกแบบฟอร์มเริ่มต้น คุณแก้ไขข้อมูลนี้ได้ภายหลังหากต้องการ คลิก บันทึกเมื่อทำเสร็จ

    4. กลับไปที่ข้อมูลเข้าสู่ระบบ > สร้างข้อมูลรับรอง > รหัสไคลเอ็นต์ OAuth ไปยัง ต่อไป

  4. เลือกแอปบนเดสก์ท็อปเป็นประเภทแอปพลิเคชัน ตั้งชื่อ แล้วคลิก สร้าง

เมื่อเสร็จแล้ว ระบบจะแสดงรหัสไคลเอ็นต์และไคลเอ็นต์ OAuth 2.0 ข้อมูลลับ ซึ่งคุณสามารถดาวน์โหลดในรูปแบบ JSON และบันทึกไว้ใช้ในภายหลัง

ติดตั้งไลบรารีของไคลเอ็นต์

Campaign Manager 360 API สร้างขึ้นด้วย HTTP และ JSON ดังนั้นไคลเอ็นต์ HTTP มาตรฐานจึงสามารถส่ง และแยกวิเคราะห์การตอบกลับได้

อย่างไรก็ตาม ไลบรารีของไคลเอ็นต์ Google API มีการผสานรวมภาษาที่ดีกว่า การรักษาความปลอดภัยที่ดียิ่งขึ้น และการสนับสนุนสำหรับการส่งคำขอที่ได้รับอนุญาต ลูกค้า ห้องสมุดพร้อมให้บริการในภาษาโปรแกรมต่างๆ เมื่อคุณใช้เครื่องมือเหล่านี้ ทำให้ไม่จำเป็นต้องตั้งค่าคำขอ HTTP และแยกวิเคราะห์การตอบกลับด้วยตนเอง

เลือกภาษาโปรแกรมที่คุณใช้ในการเริ่มต้นใช้งาน ที่กำลังพัฒนา

C#

ติดตั้งไลบรารีไคลเอ็นต์ Campaign Manager 360 API เวอร์ชันล่าสุดสำหรับ .NET การใช้ ขอแนะนำให้ใช้ NuGet เพื่อจัดการการติดตั้ง

เปิดคอนโซล NuGet Package Manager และเรียกใช้คำสั่งต่อไปนี้

Install-Package Google.Apis.Dfareporting.v3_4

ดูข้อมูลเพิ่มเติม

Java

ติดตั้งไลบรารีของไคลเอ็นต์ Campaign Manager 360 API เวอร์ชันล่าสุดสำหรับ Java การใช้ ขอแนะนำให้ใช้ Maven ในการจัดการการติดตั้ง

เพิ่มทรัพยากร Dependency ต่อไปนี้ลงในไฟล์ 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>

ดูข้อมูลเพิ่มเติม

PHP

ติดตั้งไลบรารีไคลเอ็นต์ Campaign Manager 360 API เวอร์ชันล่าสุดสำหรับ PHP การใช้ ขอแนะนำให้ใช้คอมโพสเซอร์เพื่อจัดการการติดตั้ง

เปิดเทอร์มินัลและเรียกใช้คำสั่งต่อไปนี้

composer require google/apiclient

หากคุณติดตั้งไลบรารีแล้ว และต้องการอัปเดตเป็น เวอร์ชันล่าสุด:

composer update google/apiclient

อาจต้องเพิ่มคำสั่งเหล่านี้ไว้หน้าคำสั่ง ทั้งนี้ขึ้นอยู่กับระบบของคุณ sudo

ดูข้อมูลเพิ่มเติม

Python

ติดตั้งไลบรารีของไคลเอ็นต์ Campaign Manager 360 API เวอร์ชันล่าสุดสำหรับ Python การใช้ ขอแนะนำให้ใช้ pip เพื่อจัดการการติดตั้ง

เปิดเทอร์มินัลและเรียกใช้คำสั่งต่อไปนี้

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

อาจต้องเพิ่มคำสั่งเหล่านี้ไว้หน้าคำสั่ง ทั้งนี้ขึ้นอยู่กับระบบของคุณ sudo

ดูข้อมูลเพิ่มเติม

Ruby

ติดตั้งไลบรารีไคลเอ็นต์ Campaign Manager 360 API เวอร์ชันล่าสุดสำหรับ Ruby การใช้ ขอแนะนำให้ใช้ RubyGems เพื่อจัดการการติดตั้ง

เปิดเทอร์มินัลและเรียกใช้คำสั่งต่อไปนี้

gem install google-api-client

หากคุณติดตั้งไลบรารีแล้ว และต้องการอัปเดตเป็น เวอร์ชันล่าสุด:

gem update -y google-api-client

อาจต้องเพิ่มคำสั่งเหล่านี้ไว้หน้าคำสั่ง ทั้งนี้ขึ้นอยู่กับระบบของคุณ sudo

ดูข้อมูลเพิ่มเติม

ดูภาษาอื่นๆ ที่รองรับได้ในไคลเอ็นต์ ไลบรารี

ส่งคำขอ

ใช้สร้างข้อมูลเข้าสู่ระบบ OAuth 2.0 และไลบรารีไคลเอ็นต์แล้ว ติดตั้งแล้ว คุณก็พร้อมที่จะเริ่มใช้ Campaign Manager 360 API แล้ว ดูวิธีการ เพื่อให้สิทธิ์ กำหนดค่าไคลเอ็นต์ และส่งคำขอแรกของคุณโดยทำตาม ด้านล่างนี้ได้เลย

C#

  1. โหลดไฟล์รหัสลับไคลเอ็นต์และสร้างข้อมูลเข้าสู่ระบบการให้สิทธิ์

    ครั้งแรกที่ทำขั้นตอนนี้ ระบบจะขอให้คุณยอมรับข้อความแจ้งการให้สิทธิ์ในเบราว์เซอร์ ก่อนยอมรับ โปรดตรวจสอบว่าคุณได้ลงชื่อเข้าสู่ระบบด้วยบัญชี Google ที่มีสิทธิ์เข้าถึง Campaign Manager 360 แอปพลิเคชันของคุณจะได้รับอนุญาตให้เข้าถึงข้อมูลในนามของบัญชีใดก็ตามที่ลงชื่อเข้าใช้อยู่ในขณะนี้

    // 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. สร้างไคลเอ็นต์ Dfareporting ที่ได้รับอนุญาต

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

Java

  1. โหลดไฟล์รหัสลับไคลเอ็นต์และสร้างข้อมูลเข้าสู่ระบบการให้สิทธิ์

    ครั้งแรกที่ทำขั้นตอนนี้ ระบบจะขอให้คุณยอมรับข้อความแจ้งการให้สิทธิ์ในเบราว์เซอร์ ก่อนยอมรับ โปรดตรวจสอบว่าคุณได้ลงชื่อเข้าสู่ระบบด้วยบัญชี Google ที่มีสิทธิ์เข้าถึง Campaign Manager 360 แอปพลิเคชันของคุณจะได้รับอนุญาตให้เข้าถึงข้อมูลในนามของบัญชีใดก็ตามที่ลงชื่อเข้าใช้อยู่ในขณะนี้

    // 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. สร้างไคลเอ็นต์ Dfareporting ที่ได้รับอนุญาต

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

PHP

  1. โหลดไฟล์รหัสลับไคลเอ็นต์และสร้างข้อมูลเข้าสู่ระบบการให้สิทธิ์

    ครั้งแรกที่ทำขั้นตอนนี้ ระบบจะขอให้คุณยอมรับข้อความแจ้งการให้สิทธิ์ในเบราว์เซอร์ ก่อนยอมรับ โปรดตรวจสอบว่าคุณได้ลงชื่อเข้าสู่ระบบด้วยบัญชี Google ที่มีสิทธิ์เข้าถึง Campaign Manager 360 แอปพลิเคชันของคุณจะได้รับอนุญาตให้เข้าถึงข้อมูลในนามของบัญชีใดก็ตามที่ลงชื่อเข้าใช้อยู่ในขณะนี้

    // 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. สร้างไคลเอ็นต์ Dfareporting ที่ได้รับอนุญาต

    // 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. โหลดไฟล์รหัสลับไคลเอ็นต์และสร้างข้อมูลเข้าสู่ระบบการให้สิทธิ์

    ครั้งแรกที่ทำขั้นตอนนี้ ระบบจะขอให้คุณยอมรับข้อความแจ้งการให้สิทธิ์ในเบราว์เซอร์ ก่อนยอมรับ โปรดตรวจสอบว่าคุณได้ลงชื่อเข้าสู่ระบบด้วยบัญชี Google ที่มีสิทธิ์เข้าถึง Campaign Manager 360 แอปพลิเคชันของคุณจะได้รับอนุญาตให้เข้าถึงข้อมูลในนามของบัญชีใดก็ตามที่ลงชื่อเข้าใช้อยู่ในขณะนี้

    # 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. สร้างไคลเอ็นต์ Dfareporting ที่ได้รับอนุญาต

    # 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. โหลดไฟล์รหัสลับไคลเอ็นต์และสร้างข้อมูลเข้าสู่ระบบการให้สิทธิ์

    ครั้งแรกที่ทำขั้นตอนนี้ ระบบจะขอให้คุณยอมรับข้อความแจ้งการให้สิทธิ์ในเบราว์เซอร์ ก่อนยอมรับ โปรดตรวจสอบว่าคุณได้ลงชื่อเข้าสู่ระบบด้วยบัญชี Google ที่มีสิทธิ์เข้าถึง Campaign Manager 360 แอปพลิเคชันของคุณจะได้รับอนุญาตให้เข้าถึงข้อมูลในนามของบัญชีใดก็ตามที่ลงชื่อเข้าใช้อยู่ในขณะนี้

    # 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. สร้างไคลเอ็นต์ Dfareporting ที่ได้รับอนุญาต

    # 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 ฝังอยู่ โปรแกรมสำรวจที่คุณสามารถใช้เพื่อส่งคำขอทดสอบได้โดยตรงจาก เบราว์เซอร์

ดูคำแนะนำอื่นๆ ของเราซึ่งครอบคลุมหัวข้อขั้นสูงและให้ข้อมูลตั้งแต่ต้นจนจบ ตัวอย่างสำหรับงานทั่วไป

เมื่อคุณพร้อมที่จะเริ่มเขียนโค้ด ก็ลองสำรวจหน้าอื่นๆ อย่าง ของตัวอย่างโค้ด ซึ่งอาจมีการแก้ไขและ ขยายออกให้เหมาะกับความต้องการของคุณ