একজন ক্লায়েন্ট তৈরি করুন
আপনি buyers.clients.create মেথডটি ব্যবহার করে এমন একটি Client তৈরি করতে পারেন যা আপনার কোনো একজন ক্লায়েন্টের প্রতিনিধিত্ব করবে।
Client রিসোর্স দিয়ে আপনি যে কাজগুলো করতে পারেন, তার কয়েকটি নিচে দেওয়া হলো:
- প্রকাশকদের সাথে আলোচনার সময় ক্লায়েন্টের উল্লেখ করুন।
- ক্লায়েন্টকে নিলাম প্যাকেজগুলিতে সাবস্ক্রাইব করুন।
- অনুমোদিত ক্রেতা মার্কেটপ্লেস UI-তে ক্লায়েন্টের অ্যাক্সেস পরিচালনা করুন।
নিম্নলিখিত নমুনাটি দেখায় যে আপনি ` create মেথড ব্যবহার করে কীভাবে একটি নতুন Client তৈরি করতে পারেন।
বিশ্রাম
অনুরোধ
POST https://authorizedbuyersmarketplace.googleapis.com/v1/buyers/12345678/clients?alt=json
Authorization: Bearer ACCESS_TOKEN
Content-Type: application/json
{
"displayName": "Demo Approver 2",
"role": "CLIENT_DEAL_APPROVER",
"sellerVisible": false
}প্রতিক্রিয়া
{
"name": "buyers/12345678/clients/873721984",
"role": "CLIENT_DEAL_APPROVER",
"state": "ACTIVE",
"displayName": "Demo Approver 2"
}জাভা
/* * 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 java.util.UUID; import net.sourceforge.argparse4j.ArgumentParsers; import net.sourceforge.argparse4j.inf.ArgumentParser; import net.sourceforge.argparse4j.inf.ArgumentParserException; import net.sourceforge.argparse4j.inf.Namespace; /** Creates a client for the given buyer account ID. */ public class CreateClients { public static void execute(AuthorizedBuyersMarketplace marketplaceClient, Namespace parsedArgs) { Long accountId = parsedArgs.getLong("account_id"); String parentBuyerName = String.format("buyers/%d", accountId); Client newClient = new Client(); newClient.setDisplayName(parsedArgs.getString("display_name")); newClient.setRole(parsedArgs.getString("role")); newClient.setSellerVisible(parsedArgs.getBoolean("seller_visible")); String partnerClientId = parsedArgs.getString("partner_client_id"); if (partnerClientId != null) { newClient.setPartnerClientId(partnerClientId); } Client client = null; try { client = marketplaceClient.buyers().clients().create(parentBuyerName, newClient).execute(); } catch (IOException ex) { System.out.printf("Marketplace API returned error response:%n%s", ex); System.exit(1); } System.out.printf("Created client for buyer Account ID '%d':%n", accountId); Utils.printClient(client); } public static void main(String[] args) { ArgumentParser parser = ArgumentParsers.newFor("CreateClients") .build() .defaultHelp(true) .description(("Creates a client for the given buyer account ID.")); parser .addArgument("-a", "--account_id") .help("The resource ID of the buyers resource under which the client is to be created. ") .required(true) .type(Long.class); parser .addArgument("-d", "--display_name") .help( "Display name shown to publishers. Must be unique for clients without " + "partnerClientId specified. Maximum length of 255 characters is allowed. By " + "default, this sample will specify a generated name.") .type(String.class) .setDefault(String.format("TEST_CLIENT_%s", UUID.randomUUID())); parser .addArgument("-p", "--partner_client_id") .help( "Arbitrary unique identifier provided by the buyer. This field can be used to associate" + " a client with an identifier in the namespace of the buyer. If present, it must" + " be unique across all the clients. By default, this sample will not specify a" + "partnerClientId.") .type(String.class); parser .addArgument("-r", "--role") .help( "The role assigned to the client, which determines its permissions. By default, this" + " will be set to CLIENT_DEAL_VIEWER. For more details on how to interpret the" + " different roles, see: " + "https://developers.google.com/authorized-buyers/apis/marketplace/reference/rest/v1/buyers.clients#ClientRole") .type(String.class) .setDefault("CLIENT_DEAL_VIEWER"); parser .addArgument("-s", "--seller_visible") .help( "Whether the client will be visible to publishers. By default, this sample will " + "set this to false.") .type(Boolean.class) .setDefault(false); 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); } }
একজন ক্লায়েন্টকে প্যাচ করুন
আপনি বিদ্যমান কোনো Client আপডেট করতে buyers.clients.patch মেথডটি ব্যবহার করতে পারেন। উদাহরণস্বরূপ, আপনি displayName আপডেট করতে patch ব্যবহার করতে পারেন। নিচের নমুনাটিতে দেখানো হয়েছে কিভাবে আপনি patch মেথড ব্যবহার করে একজন Client আপডেট করতে পারেন।
বিশ্রাম
অনুরোধ
PATCH https://authorizedbuyersmarketplace.googleapis.com/v1/buyers/12345678/clients/873721984?updateMask=displayName&alt=json
Authorization: Bearer ACCESS_TOKEN
Content-Type: application/json
{
"displayName": "Test Client #6a1849ca-f8ed-4ead-a3b9-75ef117b043f"
}প্রতিক্রিয়া
{
"name": "buyers/12345678/clients/873721984",
"role": "CLIENT_DEAL_APPROVER",
"state": "ACTIVE",
"displayName": "Test Client #6a1849ca-f8ed-4ead-a3b9-75ef117b043f"
}জাভা
/* * 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 java.util.UUID; import net.sourceforge.argparse4j.ArgumentParsers; import net.sourceforge.argparse4j.inf.ArgumentParser; import net.sourceforge.argparse4j.inf.ArgumentParserException; import net.sourceforge.argparse4j.inf.Namespace; /** Patches a client with the specified name. */ public class PatchClients { 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 update = new Client(); update.setDisplayName(parsedArgs.getString("display_name")); String uMask = "displayName"; Client client = null; try { client = marketplaceClient.buyers().clients().patch(name, update).setUpdateMask(uMask).execute(); } catch (IOException ex) { System.out.printf("Marketplace API returned error response:%n%s", ex); System.exit(1); } System.out.printf("Patched client for buyer Account ID '%d':%n", accountId); Utils.printClient(client); } public static void main(String[] args) { ArgumentParser parser = ArgumentParsers.newFor("PatchClients") .build() .defaultHelp(true) .description(("Patches 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.") .required(true) .type(Long.class); parser .addArgument("-c", "--client_id") .help("The resource ID of the buyers.clients resource under which the client was created.") .required(true) .type(Long.class); parser .addArgument("-d", "--display_name") .help( "Display name shown to publishers. Must be unique for clients without partnerClientId" + " specified. Maximum length of 255 characters is allowed. By default, this sample" + " will specify a generated name that will be used to patch the client's existing" + " display name.") .type(String.class) .setDefault(String.format("TEST_CLIENT_%s", UUID.randomUUID())); 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); } }