ব্যবহারকারীদের যোগ করুন এবং সরান

একটি Client অধীনে একজন স্বতন্ত্র ClientUser যোগ করতে ও অপসারণ করতে আপনি নিম্নলিখিত পদ্ধতিগুলো ব্যবহার করতে পারেন।

ব্যবহারকারী যোগ করুন

আপনি কোনো ক্লায়েন্টের পক্ষ থেকে অনুমোদিত ক্রেতা UI অ্যাক্সেস করার জন্য একজন নতুন ব্যক্তিকে আমন্ত্রণ জানাতে buyers.clients.users.create মেথডটি ব্যবহার করতে পারেন।

যখন আপনি একজন ClientUser তৈরি করেন, তখন তার state INVITED হিসেবে সেট করা হয় এবং গুগল আপনার দেওয়া ইমেইলে নিম্নলিখিতের মতো একটি আমন্ত্রণ পাঠায়:

অনুমোদিত ক্রেতা মার্কেটপ্লেস UI-তে প্রবেশাধিকার পেতে ব্যক্তিকে অবশ্যই 'আমন্ত্রণ গ্রহণ করুন ' (ACCEPT INVITATION) বোতামে ক্লিক করতে হবে। অনুমোদিত ক্রেতা মার্কেটপ্লেস UI-তে প্রবেশ করার জন্য আপনাকে অবশ্যই একটি গুগল অ্যাকাউন্টে সাইন ইন করতে হবে।

নিম্নলিখিত নমুনাটি দেখায় যে আপনি কীভাবে create মেথড ব্যবহার করে একজন নতুন ClientUser যোগ করতে পারেন।

বিশ্রাম

অনুরোধ

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

{
 "email": "james@luxurymarscruises.mars"
}

প্রতিক্রিয়া

{
 "name": "buyers/12345678/clients/873721984/users/4683251",
 "state": "INVITED",
 "email": "james@luxurymarscruises.mars"
}

জাভা

/*
 * 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.authorizedbuyersmarketplace.v1.model.ClientUser;
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;
import org.apache.commons.lang3.RandomUtils;

/**
 * Creates a client user for the given client.
 *
 * <p>When a client user is created, the specified email address will receive an email to confirm
 * access to the Authorized Buyers UI. It will remain in the "INVITED" state and be unable to access
 * the UI until the specified email has approved of the change.
 */
public class CreateClientUsers {

  public static void execute(AuthorizedBuyersMarketplace marketplaceClient, Namespace parsedArgs) {
    Long accountId = parsedArgs.getLong("account_id");
    Long clientId = parsedArgs.getLong("client_id");

    String parentClientName = String.format("buyers/%d/clients/%d", accountId, clientId);

    ClientUser newClientUser = new ClientUser();
    newClientUser.setEmail(parsedArgs.getString("email"));

    ClientUser clientUser = null;
    try {
      clientUser =
          marketplaceClient
              .buyers()
              .clients()
              .users()
              .create(parentClientName, newClientUser)
              .execute();
    } catch (IOException ex) {
      System.out.printf("Marketplace API returned error response:%n%s", ex);
      System.exit(1);
    }

    System.out.printf("Created client user for client with name \"%s\":%n", parentClientName);
    Utils.printClientUser(clientUser);
  }

  public static void main(String[] args) {
    RandomUtils rng = new RandomUtils();

    ArgumentParser parser =
        ArgumentParsers.newFor("CreateClientUsers")
            .build()
            .defaultHelp(true)
            .description(("Creates a client user for the given buyer and client ID."));
    parser
        .addArgument("-a", "--account_id")
        .help(
            "The resource ID of the buyers resource under which the client user is to be created."
                + " This will be used to construct the name used as a path parameter for the"
                + " users.create 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 is to be"
                + " created. This will be used to construct the name used as a path parameter for"
                + " the users.create request.")
        .required(true)
        .type(Long.class);
    parser
        .addArgument("-e", "--email")
        .help(
            "The client user's email address that has to be unique across all client users for "
                + "a given client. By default, this will be set to a randomly generated email for "
                + "demonstration purposes.")
        .type(String.class)
        .setDefault(String.format("testemail%s@test.com", rng.nextInt(10000000, 99999999)));

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

ব্যবহারকারীকে সরান

আপনি একজন ClientUser অপসারণ করতে buyers.clients.users.delete মেথডটি ব্যবহার করতে পারেন।

উদাহরণস্বরূপ, আপনি কোনো নির্দিষ্ট ক্লায়েন্টের জন্য অনুমোদিত ক্রেতা মার্কেটপ্লেস UI-তে কোনো ব্যক্তির অ্যাক্সেস স্থায়ীভাবে বাতিল করতে delete ব্যবহার করতে পারেন।

কোনো ClientUser সরিয়ে দেওয়ার পর, আপনাকে একটি নতুন ClientUser তৈরি করতে হবে এবং অথরাইজড বায়ার্স মার্কেটপ্লেস UI-তে পুনরায় অ্যাক্সেস পেতে হলে সেই ব্যক্তিকে একটি নতুন আমন্ত্রণ গ্রহণ করতে হবে।

নিম্নলিখিত নমুনাটি দেখায় কিভাবে আপনি delete মেথড ব্যবহার করে একজন ClientUser ডিলিট করতে পারেন।

বিশ্রাম

অনুরোধ

DELETE https://authorizedbuyersmarketplace.googleapis.com/v1/buyers/12345678/clients/873721984/users/4573638?alt=json
Authorization: Bearer ACCESS_TOKEN
Content-Type: application/json

প্রতিক্রিয়া

{}

জাভা

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