Xem các khách hàng

Bạn có thể sử dụng các phương thức sau để xem hiện có clients trong tài khoản của mình.

Xem từng ứng dụng khách

Bạn có thể sử dụng buyers.clients.get phương thức để truy xuất một Client cụ thể và xem cấp truy cập của họ vào Giao diện người dùng Thị trường người mua được uỷ quyền.

Ví dụ: khi thương lượng một đề xuất với nhà xuất bản, bạn có thể sử dụng get để xem thông tin về Client được chỉ định trong đề xuất.

Mẫu sau đây minh hoạ cách bạn có thể truy xuất từng Client bằng phương thức get.

REST

Yêu cầu

GET https://authorizedbuyersmarketplace.googleapis.com/v1/buyers/12345678/clients/984287215?alt=json
Authorization: Bearer ACCESS_TOKEN
Content-Type: application/json

Phản hồi

{
 "name": "buyers/12345678/clients/984287215",
 "role": "CLIENT_DEAL_APPROVER",
 "state": "ACTIVE",
 "displayName": "Demo Approver 1"
}

Java

/*
 * Copyright 2021 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;

import com.google.api.services.authorizedbuyersmarketplace.v1.AuthorizedBuyersMarketplace;
import com.google.api.services.authorizedbuyersmarketplace.v1.model.Client;
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 get a single client for the given buyer account ID and client ID.
 */
public class GetClients {

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

    Client client = null;

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

    System.out.printf(
        "Found Client with ID \"%s\" for buyer account ID '%d':%n", clientId, accountId);
    Utils.printClient(client);
  }

  public static void main(String[] args) {
    ArgumentParser parser =
        ArgumentParsers.newFor("GetClients")
            .build()
            .defaultHelp(true)
            .description(("Get a client for the given buyer account ID and client ID."));
    parser
        .addArgument("-a", "--account_id")
        .help(
            "The resource ID of the buyers resource under which the client was created. This will"
                + " be used to construct the parent used as a path parameter for the clients.get "
                + "request.")
        .required(true)
        .type(Long.class);
    parser
        .addArgument("-c", "--client_id")
        .help(
            "The resource ID of the buyers.clients resource for which the client was created "
                + "This will be used to construct the name used as a path parameter for the "
                + "clients.get 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 ứng dụng khách

Bạn có thể sử dụng buyers.clients.list phương thức để phân trang qua tất cả ứng dụng khách hoặc tìm một ứng dụng khách được liên kết với một trong các khách hàng của bạn bằng cách sử dụng filter với partnerClientId.

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

REST

Yêu cầu

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

Phản hồi

{
 "clients": [
   {
     "name": "buyers/12345678/clients/995152331",
     "role": "CLIENT_DEAL_NEGOTIATOR",
     "state": "ACTIVE",
     "displayName": "Demo Negotiator 1",
     "partnerClientId": "pcid-5e845421-251a-4a0c-8316-67f9b8140d3a"
   },
   {
     "name": "buyers/12345678/clients/837492105",
     "role": "CLIENT_DEAL_VIEWER",
     "state": "INACTIVE",
     "displayName": "Demo Viewer 1",
     "sellerVisible": true
   },
   {
     "name": "buyers/12345678/clients/984287215",
     "role": "CLIENT_DEAL_APPROVER",
     "state": "ACTIVE",
     "displayName": "Demo Approver 1"
   }
 ],
 "nextPageToken": "CAMQ26Xgn7nb9gIY26Xgn7nb9gI="
}

Java

/*
 * Copyright 2021 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;

import com.google.api.services.authorizedbuyersmarketplace.v1.AuthorizedBuyersMarketplace;
import com.google.api.services.authorizedbuyersmarketplace.v1.model.Client;
import com.google.api.services.authorizedbuyersmarketplace.v1.model.ListClientsResponse;
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 Clients for a given buyer account ID. */
public class ListClients {

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

    System.out.printf("Found Clients for buyer Account ID '%d':%n", accountId);

    do {
      List<Client> clients = null;

      try {
        ListClientsResponse response =
            marketplaceClient
                .buyers()
                .clients()
                .list(parentBuyerName)
                .setFilter(parsedArgs.getString("filter"))
                .setPageSize(pageSize)
                .setPageToken(pageToken)
                .execute();

        clients = response.getClients();
        pageToken = response.getNextPageToken();
      } catch (IOException ex) {
        System.out.printf("Marketplace API returned error response:%n%s", ex);
        System.exit(1);
      }
      if (clients == null) {
        System.out.println("No clients found.");
      } else {
        for (Client client : clients) {
          Utils.printClient(client);
        }
      }
    } while (pageToken != null);
  }

  public static void main(String[] args) {
    ArgumentParser parser =
        ArgumentParsers.newFor("ListClients")
            .build()
            .defaultHelp(true)
            .description(("Lists clients associated with the given buyer account."));
    parser
        .addArgument("-a", "--account_id")
        .help(
            "The resource ID of the buyers resource under which the clients were created. "
                + "This will be used to construct the parent used as a path parameter for the "
                + "clients.list request.")
        .required(true)
        .type(Long.class);
    parser
        .addArgument("-f", "--filter")
        .help(
            "Query string to filter clients. If no filter is specified, all clients will be "
                + "returned. By default, no filter will be set.");
    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);
  }
}