Xem các giao dịch đang diễn ra

Bạn có thể sử dụng các phương thức sau để xem các giao dịch đang diễn ra cho tài khoản người mua của bạn và bất kỳ khách hàngnào của bạn.

Xem từng giao dịch

Bạn có thể sử dụng phương thức buyers.proposals.deals.get để truy xuất một Deal cụ thể được liên kết với một đề xuất cho tài khoản người mua của bạn hoặc một trong các khách hàng của bạn.

Mẫu sau đây minh hoạ cách bạn có thể truy xuất một Deal riêng lẻ bằng phương thức get.

REST

Yêu cầu

GET https://authorizedbuyersmarketplace.googleapis.com/v1/buyers/12345678/proposals/MP21673270/deals/52404?alt=json
Authorization: Bearer ACCESS_TOKEN
Content-Type: application/json

Phản hồi

{
 "name": "buyers/12345678/proposals/MP21673270/deals/52404",
 "createTime": "2036-12-27T04:02:39.731Z",
 "updateTime": "2036-12-27T04:03:51.097Z",
 "proposalRevision": "4",
 "displayName": "test_deal_7435251",
 "buyer": "buyers/12345678",
 "publisherProfile": "buyers/12345678/publisherProfiles/PP54321",
 "flightStartTime": "2036-12-28T00:00:00Z",
 "flightEndTime": "2036-12-30T23:59:00Z",
 "targeting": {
   "inventorySizeTargeting": {
     "targetedInventorySizes": [
       {
         "width": "1024",
         "height": "768",
         "type": "PIXEL"
       }
     ]
   }
 },
 "creativeRequirements": {
   "creativePreApprovalPolicy": "SELLER_PRE_APPROVAL_NOT_REQUIRED",
   "creativeSafeFrameCompatibility": "COMPATIBLE",
   "programmaticCreativeSource": "ADVERTISER",
   "creativeFormat": "DISPLAY"
 },
 "deliveryControl": {
   "deliveryRateType": "EVENLY"
 },
 "billedBuyer": "buyers/12345678",
 "dealType": "PROGRAMMATIC_GUARANTEED",
 "programmaticGuaranteedTerms": {
   "guaranteedLooks": "100",
   "fixedPrice": {
     "type": "CPM",
     "amount": {
       "currencyCode": "CNY",
       "units": "10"
     }
   },
   "reservationType": "STANDARD"
 },
 "sellerTimeZone": {
   "id": "Asia/Shanghai"
 }
}

Java

/*
 * Copyright 2022 Google LLC
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *    https://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.google.api.services.samples.authorizedbuyers.marketplace.v1.buyers.clients.users;

import com.google.api.services.authorizedbuyersmarketplace.v1.AuthorizedBuyersMarketplace;
import com.google.api.services.samples.authorizedbuyers.marketplace.v1.Utils;
import java.io.IOException;
import java.security.GeneralSecurityException;
import net.sourceforge.argparse4j.ArgumentParsers;
import net.sourceforge.argparse4j.inf.ArgumentParser;
import net.sourceforge.argparse4j.inf.ArgumentParserException;
import net.sourceforge.argparse4j.inf.Namespace;

/**
 * This sample illustrates how to delete a client user for the given buyer, client, and user IDs.
 */
public class DeleteClientUsers {

  public static void execute(AuthorizedBuyersMarketplace marketplaceClient, Namespace parsedArgs) {
    Long accountId = parsedArgs.getLong("account_id");
    Long clientId = parsedArgs.getLong("client_id");
    Long clientUserId = parsedArgs.getLong("client_user_id");
    String name = String.format("buyers/%d/clients/%d/users/%d", accountId, clientId, clientUserId);

    try {
      marketplaceClient.buyers().clients().users().delete(name).execute();
    } catch (IOException ex) {
      System.out.printf("Marketplace API returned error response:%n%s", ex);
      System.exit(1);
    }

    System.out.printf("Deleted client user with name \"%s\":%n", name);
  }

  public static void main(String[] args) {
    ArgumentParser parser =
        ArgumentParsers.newFor("DeactivateClientUsers")
            .build()
            .defaultHelp(true)
            .description(("Delete a client user with the given buyer, client, and user ID."));
    parser
        .addArgument("-a", "--account_id")
        .help(
            "The resource ID of the buyers resource under which the parent client was created. "
                + "This will be used to construct the name used as a path parameter for the "
                + "users.delete request.")
        .required(true)
        .type(Long.class);
    parser
        .addArgument("-c", "--client_id")
        .help(
            "The resource ID of the buyers.clients resource under which the client user was"
                + " created. This will be used to construct the name used as a path parameter for"
                + " the users.delete request.")
        .required(true)
        .type(Long.class);
    parser
        .addArgument("-u", "--client_user_id")
        .help(
            "The resource ID of the buyers.clients.users resource that is being deleted. "
                + "This will be used to construct the name used as a path parameter for the "
                + "users.delete request.")
        .required(true)
        .type(Long.class);

    Namespace parsedArgs = null;
    try {
      parsedArgs = parser.parseArgs(args);
    } catch (ArgumentParserException ex) {
      parser.handleError(ex);
      System.exit(1);
    }

    AuthorizedBuyersMarketplace client = null;
    try {
      client = Utils.getMarketplaceClient();
    } catch (IOException ex) {
      System.out.printf("Unable to create Marketplace API service:%n%s", ex);
      System.out.println("Did you specify a valid path to a service account key file?");
      System.exit(1);
    } catch (GeneralSecurityException ex) {
      System.out.printf("Unable to establish secure HttpTransport:%n%s", ex);
      System.exit(1);
    }

    execute(client, parsedArgs);
  }
}

Liệt kê nhiều giao dịch

Bạn có thể sử dụng buyers.proposals.deals.list phương thức để phân trang qua tất cả các giao dịch được liên kết với một đề xuất cho tài khoản của bạn hoặc một trong các khách hàng của bạn.

Mẫu sau đây minh hoạ cách bạn có thể liệt kê các giao dịch bằng phương thức list.

REST

Yêu cầu

GET https://authorizedbuyersmarketplace.googleapis.com/v1/buyers/12345678/proposals/MP21673270/deals?pageSize=50&alt=json
Authorization: Bearer ACCESS_TOKEN
Content-Type: application/json

Phản hồi

{
 "deals": [
   {
     "name": "buyers/12345678/proposals/MP21673270/deals/52404",
     "createTime": "2036-12-27T04:02:39.731Z",
     "updateTime": "2036-12-27T04:03:51.097Z",
     "proposalRevision": "4",
     "displayName": "test_deal_7435251",
     "buyer": "buyers/12345678",
     "publisherProfile": "buyers/12345678/publisherProfiles/PP54321",
     "flightStartTime": "2036-12-28T00:00:00Z",
     "flightEndTime": "2036-12-30T23:59:00Z",
     "targeting": {
       "inventorySizeTargeting": {
         "targetedInventorySizes": [
           {
             "width": "1024",
             "height": "768",
             "type": "PIXEL"
           }
         ]
       }
     },
     "creativeRequirements": {
       "creativePreApprovalPolicy": "SELLER_PRE_APPROVAL_NOT_REQUIRED",
       "creativeSafeFrameCompatibility": "COMPATIBLE",
       "programmaticCreativeSource": "ADVERTISER",
       "creativeFormat": "DISPLAY"
     },
     "deliveryControl": {
       "deliveryRateType": "EVENLY"
     },
     "billedBuyer": "buyers/12345678",
     "dealType": "PROGRAMMATIC_GUARANTEED",
     "programmaticGuaranteedTerms": {
       "guaranteedLooks": "100",
       "fixedPrice": {
         "type": "CPM",
         "amount": {
           "currencyCode": "CNY",
           "units": "10"
         }
       },
       "reservationType": "STANDARD"
     },
     "sellerTimeZone": {
       "id": "Asia/Shanghai"
     }
   }
 ]
}

Java

/*
 * Copyright 2022 Google LLC
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *    https://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.google.api.services.samples.authorizedbuyers.marketplace.v1.buyers.proposals.deals;

import com.google.api.services.authorizedbuyersmarketplace.v1.AuthorizedBuyersMarketplace;
import com.google.api.services.authorizedbuyersmarketplace.v1.model.Deal;
import com.google.api.services.authorizedbuyersmarketplace.v1.model.ListDealsResponse;
import com.google.api.services.samples.authorizedbuyers.marketplace.v1.Utils;
import java.io.IOException;
import java.security.GeneralSecurityException;
import java.util.List;
import net.sourceforge.argparse4j.ArgumentParsers;
import net.sourceforge.argparse4j.inf.ArgumentParser;
import net.sourceforge.argparse4j.inf.ArgumentParserException;
import net.sourceforge.argparse4j.inf.Namespace;

/** This sample illustrates how to list deals for the given buyer's proposal. */
public class ListDeals {

  public static void execute(AuthorizedBuyersMarketplace marketplaceClient, Namespace parsedArgs) {
    Long accountId = parsedArgs.getLong("account_id");
    String proposalId = parsedArgs.getString("proposal_id");
    Integer pageSize = parsedArgs.getInt("page_size");
    String parent = String.format("buyers/%d/proposals/%s", accountId, proposalId);
    String pageToken = null;

    System.out.printf("Found deals for proposal with name \"%s\":%n", parent);

    do {
      List<Deal> deals = null;

      try {
        ListDealsResponse response =
            marketplaceClient
                .buyers()
                .proposals()
                .deals()
                .list(parent)
                .setPageSize(pageSize)
                .setPageToken(pageToken)
                .execute();

        deals = response.getDeals();
        pageToken = response.getNextPageToken();
      } catch (IOException ex) {
        System.out.printf("Marketplace API returned error response:%n%s", ex);
        System.exit(1);
      }
      if (deals == null) {
        System.out.println("No proposals found.");
      } else {
        for (Deal deal : deals) {
          Utils.printDeal(deal);
        }
      }
    } while (pageToken != null);
  }

  public static void main(String[] args) {
    ArgumentParser parser =
        ArgumentParsers.newFor("ListDeals")
            .build()
            .defaultHelp(true)
            .description(("Lists deals for the given buyer's proposal."));
    parser
        .addArgument("-a", "--account_id")
        .help(
            "The resource ID of the buyers resource under which the deals are being retrieved. This"
                + " will be used to construct the parent used as a path parameter for the"
                + " deals.list request.")
        .required(true)
        .type(Long.class);
    parser
        .addArgument("--proposal_id")
        .help(
            "The resource ID of the buyers.proposals resource under which the deals are being"
                + " retrieved. This will be used to construct the parent used as a path parameter"
                + " for the deals.list request.")
        .required(true);
    parser
        .addArgument("-p", "--page_size")
        .help(
            "The number of rows to return per page. The server may return fewer rows than "
                + "specified.")
        .setDefault(Utils.getMaximumPageSize())
        .type(Integer.class);

    Namespace parsedArgs = null;
    try {
      parsedArgs = parser.parseArgs(args);
    } catch (ArgumentParserException ex) {
      parser.handleError(ex);
      System.exit(1);
    }

    AuthorizedBuyersMarketplace client = null;
    try {
      client = Utils.getMarketplaceClient();
    } catch (IOException ex) {
      System.out.printf("Unable to create Marketplace API service:%n%s", ex);
      System.out.println("Did you specify a valid path to a service account key file?");
      System.exit(1);
    } catch (GeneralSecurityException ex) {
      System.out.printf("Unable to establish secure HttpTransport:%n%s", ex);
      System.exit(1);
    }

    execute(client, parsedArgs);
  }
}