ডেভেলপার হিসেবে নিবন্ধন করা একটি বাধ্যতামূলক, এককালীন সেটআপ প্রক্রিয়া যা আপনার Google ক্লাউড প্রোজেক্টকে আপনার মার্চেন্ট সেন্টার অ্যাকাউন্টের সাথে লিঙ্ক করে এবং আপনার ডেভেলপারের যোগাযোগের তথ্য Google-এর সাথে নিবন্ধিত করে। এর ফলে Google প্রাসঙ্গিক প্রযুক্তিগত তথ্যে গুরুত্বপূর্ণ পরিষেবা ঘোষণা এবং বাধ্যতামূলক আপডেট পাঠাতে পারে।
আপনার প্রদত্ত পরিচিতি।
এই ডকুমেন্টটি মার্চেন্ট এপিআই দিয়ে শুরু করার বিষয়ে একটি বহু-অংশ সিরিজের অংশ। যদি আপনি ইতিমধ্যেই মার্চেন্ট এপিআই দিয়ে নিবন্ধিত হয়ে থাকেন, তাহলে আপনি পরবর্তী বিভাগে যেতে পারেন: আপনার প্রথম পণ্যটি সন্নিবেশ করুন
পূর্বশর্ত
মার্চেন্ট এপিআই ব্যবহার করার জন্য নিবন্ধন করার আগে, নিশ্চিত করুন যে আপনি নিম্নলিখিত প্রয়োজনীয়তাগুলি পূরণ করছেন:
- মার্চেন্ট সেন্টার অ্যাকাউন্ট : আপনার একটি বিদ্যমান মার্চেন্ট সেন্টার অ্যাকাউন্ট থাকা প্রয়োজন।
- মার্চেন্ট সেন্টার অ্যাকাউন্টে অ্যাডমিন অ্যাক্সেস : রেজিস্ট্রেশন কল অনুমোদনের জন্য আপনি যে ইমেল বা পরিষেবা অ্যাকাউন্ট ব্যবহার করেন তাতে আপনার নিবন্ধিত মার্চেন্ট সেন্টার অ্যাকাউন্টে
ADMINঅ্যাক্সেস টাইপ থাকতে হবে। আরও তথ্যের জন্য, মার্চেন্ট API-তে অনুরোধ অনুমোদন দেখুন। - গুগল ক্লাউড প্রজেক্ট আইডি : প্রমাণীকরণের জন্য শংসাপত্র প্রদানের জন্য আপনার অ্যাপ্লিকেশনটিকে একটি ডেডিকেটেড গুগল ক্লাউড প্রজেক্টের সাথে যুক্ত থাকতে হবে। প্রজেক্ট আইডি কোথায় পাবেন সে সম্পর্কে বিস্তারিত জানতে, প্রজেক্টের নাম, নম্বর এবং আইডি খুঁজুন দেখুন।
- Google থেকে আপডেটের জন্য ডেভেলপারের সাথে যোগাযোগের জন্য আপনার দেওয়া Google অ্যাকাউন্টের সাথে সম্পর্কিত একটি বৈধ ইমেল ঠিকানা । এটি কোনও পরিষেবা অ্যাকাউন্টের ইমেল ঠিকানা হতে হবে না। আপনি এমন একটি ইমেল ঠিকানা ব্যবহার করতে পারেন যা ইতিমধ্যেই Merchant Center অ্যাকাউন্টের অংশ অথবা একটি নতুন অ্যাকাউন্ট।
মার্চেন্ট এপিআই দিয়ে ডেভেলপার হিসেবে নিবন্ধন করুন
মার্চেন্ট এপিআই ব্যবহার করার জন্য, আপনাকে registerGcp পদ্ধতির মাধ্যমে আপনার ডেভেলপারের যোগাযোগের তথ্য এবং গুগল ক্লাউড প্রকল্প আপনার মার্চেন্ট সেন্টার অ্যাকাউন্টের সাথে নিবন্ধন করতে হবে ।
আপনি একাধিক মার্চেন্ট অ্যাকাউন্ট নিয়ে কাজ করুন বা না করুন, আপনি যে প্রতিটি গুগল ক্লাউড প্রকল্প ব্যবহার করতে চান তার জন্য আপনাকে একবার নিবন্ধন প্রক্রিয়াটি সম্পাদন করতে হবে । আপনি যদি একাধিক গুগল ক্লাউড প্রকল্প নিয়ে কাজ করেন, তাহলে আপনি একই মার্চেন্ট সেন্টার অ্যাকাউন্টে যেকোনো একটি বা সমস্ত নিবন্ধন করতে পারেন।
নিবন্ধনের সুবিধা
নিবন্ধন নিম্নলিখিত সুবিধা প্রদান করে:
- প্রযুক্তিগত যোগাযোগ তৈরি : এটি মার্চেন্ট সেন্টারে একটি প্রযুক্তিগত যোগাযোগ তৈরি করে। গুগল প্রযুক্তিগত যোগাযোগের জন্য গুরুত্বপূর্ণ API-নির্দিষ্ট আপডেট পাঠায়, যেমন পরিষেবা ঘোষণা এবং নতুন বৈশিষ্ট্য সম্পর্কিত তথ্য।
- একাধিক মার্চেন্ট অ্যাকাউন্ট ব্যবস্থাপনা : এটি আপনাকে আপনার পরিচালিত সমস্ত মার্চেন্ট অ্যাকাউন্টের জন্য ডেভেলপারের যোগাযোগের স্থান উপস্থাপন করতে দেয়।
রেজিস্ট্রেশন ছাড়া, একটি অনিবন্ধিত Google ক্লাউড প্রকল্প থেকে Merchant API-তে যেকোনো কল ব্লক করা হয়, যার ফলে একটি 401 ত্রুটি কোড ফিরে আসে যার স্ট্যাটাস UNAUTHENTICATED এবং নিম্নলিখিত ত্রুটি বার্তা থাকে:
GCP project with id {GCP_ID} and number {GCP_NUMBER} is not registered with the merchant account.
Please follow these steps https://developers.google.com/merchant/api/guides/quickstart#register_as_a_developer
to register the GCP project with the merchant account then try calling the API again in 5 minutes.
গুরুত্বপূর্ণ বিবেচ্য বিষয়
- প্রতিটি গুগল ক্লাউড প্রোজেক্টের জন্য এককালীন সেটআপ : নিবন্ধন হল প্রতিটি গুগল ক্লাউড প্রোজেক্টের জন্য এককালীন সেটআপ, এবং এটি গুগল ক্লাউড প্রোজেক্টের মধ্যে সমস্ত ব্যবহারকারী এবং পরিষেবা অ্যাকাউন্টের জন্য প্রযোজ্য। নিশ্চিত করুন যে আপনার গুগল ক্লাউড প্রোজেক্টে মার্চেন্ট API সক্ষম করা আছে।
- প্রতিটি Google ক্লাউড প্রকল্প যেকোনো সময় শুধুমাত্র একটি একক Merchant Center অ্যাকাউন্ট দিয়ে নিবন্ধিত হতে পারে : আপনি যদি একই সাথে একাধিক Merchant Center অ্যাকাউন্ট দিয়ে একটি Google ক্লাউড প্রকল্প নিবন্ধন করার চেষ্টা করেন, তাহলে আপনি একটি
ALREADY_REGISTEREDত্রুটি পাবেন। নিবন্ধনের জন্য একই ডেভেলপার ইমেল ঠিকানা ব্যবহার করুন। মনে রাখবেন যে একাধিক Google ক্লাউড প্রকল্প একই Merchant Center অ্যাকাউন্টে নিবন্ধিত হতে পারে। - একাধিক বণিক পরিচালনাকারী তৃতীয় পক্ষের (3Ps) জন্য সঠিক অ্যাকাউন্ট নির্ধারণ করুন: একাধিক বণিকের প্রতিনিধিত্বকারী বা পরিচালনাকারী তৃতীয় পক্ষগুলিকে Google ইকোসিস্টেমের মধ্যে উপযুক্ত অ্যাকাউন্ট কাঠামো ব্যবহার করতে হবে। সঠিক আইডি ব্যবহার আপনার ব্যবসার ধরণের উপর নির্ভর করে:
- বিদ্যমান অ্যাডভান্সড অ্যাকাউন্ট সহ মার্কেটপ্লেস: যদি আপনার ব্যবসা একটি মার্কেটপ্লেস হিসেবে পরিচালিত হয় এবং ইতিমধ্যেই পুরো প্ল্যাটফর্মের প্রতিনিধিত্বকারী একটি অ্যাডভান্সড অ্যাকাউন্ট থাকে, তাহলে আপনার এই বিদ্যমান অ্যাকাউন্ট আইডিটি ব্যবহার করা উচিত।
- তুলনামূলক শপিং সার্ভিসেস (CSS): আপনি যদি একজন CSS হন, তাহলে আপনার অনন্য CSS অ্যাকাউন্ট আইডি অথবা CSS গ্রুপ অ্যাকাউন্ট আইডি ব্যবহার করা উচিত।
- এজেন্সি, ডেভেলপার এবং অন্যান্য 3P: যদি আপনি একটি 3P ব্যবসা হন যেমন এজেন্সি বা তৃতীয় পক্ষের ডেভেলপার একাধিক মার্চেন্ট অ্যাকাউন্ট পরিচালনা করে এবং আপনার ব্যবসার প্রতিনিধিত্বকারী একটিও মার্চেন্ট সেন্টার আইডি না থাকে, তাহলে আপনার একটি নতুন, প্রাথমিক মার্চেন্ট সেন্টার অ্যাকাউন্ট তৈরি করা উচিত এবং এটিকে একটি অ্যাডভান্সড অ্যাকাউন্টে রূপান্তর করার অনুরোধ করা উচিত। অ্যাডভান্সড অ্যাকাউন্টগুলি সাবঅ্যাকাউন্ট পরিচালনা করতে পারে এবং 3P ক্রিয়াকলাপের জন্য প্রয়োজনীয় কাঠামো প্রদান করতে পারে।
- শুধুমাত্র আপনার প্রাথমিক মার্চেন্ট সেন্টারের জন্য নিবন্ধন করুন : আপনি শুধুমাত্র আপনার প্রাথমিক মার্চেন্ট সেন্টার অ্যাকাউন্ট ব্যবহার করে ডেভেলপার নিবন্ধন করেন এবং আপনি লিঙ্ক করা সমস্ত মার্চেন্ট সেন্টার সাবঅ্যাকাউন্টের জন্য ডেভেলপার যোগাযোগ হন। আপনার প্রতিটি মার্চেন্ট সেন্টার সাবঅ্যাকাউন্টের জন্য নিবন্ধন করবেন না।

পূর্ববর্তী চিত্রটি একাধিক Google ক্লাউড প্রকল্প এবং ঐচ্ছিকভাবে একাধিক Merchant Center উপ-অ্যাকাউন্ট সহ একটি প্রাথমিক Merchant Center ব্যবহার করার সময় নিবন্ধন সেটআপ দেখায়।
- একবার আপনি একজন ডেভেলপারের ইমেল ঠিকানা নিবন্ধন করলে :
- আপনি নিবন্ধনের ৫ মিনিটের মধ্যে মার্চেন্ট এপিআই কল করতে পারবেন।
- যদি ইমেলটি কোনও বিদ্যমান মার্চেন্ট সেন্টার ব্যবহারকারীর হয়, তাহলে তাদের
API_DEVELOPERভূমিকা দেওয়া হবে। অন্যথায়, মার্চেন্ট সেন্টারে একটি নতুন ব্যবহারকারী তৈরি করা হবে এবং তাদের ১৪ দিনের মধ্যে একটি আমন্ত্রণ গ্রহণ করতে হবে যাতে এটির মেয়াদ শেষ না হয় এবং নিবন্ধন প্রক্রিয়া পুনরায় শুরু করতে না হয়। ব্যবহারকারী আমন্ত্রণ লিঙ্কে ক্লিক করার পরেই আপনি নিবন্ধন প্রক্রিয়াটি সম্পূর্ণ করবেন।
রেজিস্ট্রেশনের জন্য কল করুন।
আপনি registerGcp পদ্ধতিতে কল করে নিবন্ধন করতে পারেন। নিবন্ধন কল করার জন্য আপনার কাছে দুটি বিকল্প রয়েছে:
- বিকল্প ১: সরাসরি API কল আপনি API এন্ডপয়েন্টগুলিতে সরাসরি অনুরোধ করেন, সাধারণত HTTP(S) এর মাধ্যমে। আপনি অনুরোধের বডি তৈরি করা, হেডার সেট করা (প্রমাণীকরণ সহ), এবং প্রতিক্রিয়া বিশ্লেষণ করার মতো দিকগুলি ম্যানুয়ালি পরিচালনা করেন।
- বিকল্প ২: ক্লায়েন্ট লাইব্রেরি আপনি পূর্বনির্মিত লাইব্রেরি ব্যবহার করেন যা মার্চেন্ট API-এর সাথে ইন্টারঅ্যাক্ট করার জন্য আরও সুবিধাজনক, ভাষা-বাক্যগত উপায় অফার করে। তারা প্রমাণীকরণ এবং অনুমোদন পরিচালনা করে এবং অন্তর্নিহিত HTTP যোগাযোগকে বিমূর্ত করার একটি সুবিধাজনক উপায় অফার করে। আপনাকে দ্রুত শুরু করার জন্য অফিসিয়াল কোড নমুনা উপলব্ধ।
নিবন্ধন কলের জন্য অনুমোদন
"Merchant API-তে অনুরোধ অনুমোদন" ধাপে বর্ণিত হিসাবে, আপনার দুটি স্বতন্ত্র প্রমাণীকরণ পরিস্থিতি রয়েছে:
- OAuth 2.0 : একাধিক মার্চেন্ট অ্যাকাউন্ট পরিচালনাকারী তৃতীয় পক্ষের সরবরাহকারী বা সংস্থাগুলির জন্য
- পরিষেবা অ্যাকাউন্ট : আপনার নিজস্ব মার্চেন্ট সেন্টার অ্যাকাউন্টে অ্যাক্সেসের জন্য
রেজিস্ট্রেশন কলের অনুমোদন সম্পর্কে আরও তথ্যের জন্য, রেজিস্ট্রেশন কলের জন্য আমি কীভাবে প্রমাণীকরণ এবং অনুমোদন করব? দেখুন।
নিবন্ধন কল
নিম্নলিখিত উদাহরণগুলিতে, আপনি সরাসরি এপিআই কল বা ক্লায়েন্ট লাইব্রেরি ব্যবহার করে নিবন্ধন কল সম্পাদন করেন।
আপনি registerGcp পদ্ধতি ব্যবহার করে নিবন্ধন কলটি সম্পাদন করেন।
POST https://merchantapi.googleapis.com/accounts/v1/accounts/{ACCOUNT_ID}/developerRegistration:registerGcp
Content-Type: application/json
Authorization: Bearer {ACCESS_TOKEN}"
{
"developerEmail": "{DEVELOPER_EMAIL}"
}
নিম্নলিখিতগুলি প্রতিস্থাপন করুন:
-
ACCOUNT_ID: আপনার মার্চেন্ট সেন্টার আইডি -
ACCESS_TOKEN: API কল করার জন্য অনুমোদন টোকেন -
DEVELOPER_EMAIL: প্রাথমিক প্রযুক্তিগত যোগাযোগের ইমেল ঠিকানা
একটি সফল কল একটি ডেভেলপাররেজিস্ট্রেশন রিসোর্স ফেরত পাঠায়, যা সফল লিঙ্কিং স্ট্যাটাস নিশ্চিত করে:
"name": "accounts/{ACCOUNT_ID}/developerRegistration",
"gcpIds": ["{GOOGLE_CLOUD_PROJECT_ID}"]
পাইথন
নমুনাগুলি ডাউনলোড করুন এবং পাইথন ক্লায়েন্ট লাইব্রেরি সেট আপ করতে Google Merchant API Python Samples থেকে নির্দেশিকা অনুসরণ করুন।
from examples.authentication import configuration
from examples.authentication import generate_user_credentials
from google.shopping.merchant_accounts_v1 import DeveloperRegistrationServiceClient
from google.shopping.merchant_accounts_v1 import RegisterGcpRequest
def register_gcp(account_id: str, developer_email: str) -> None:
"""Registers the GCP project used to call the Merchant API with a developer email.
Args:
account_id: The ID of your Merchant Center account.
developer_email: The email address of the developer to register.
"""
# Get OAuth credentials.
credentials = generate_user_credentials.main()
# Create a client to the Developer Registration Service.
client = DeveloperRegistrationServiceClient(credentials=credentials)
# The name has the format: accounts/{account}/developerRegistration
name = f"accounts/{account_id}/developerRegistration"
# Create the request to register the GCP project.
request = RegisterGcpRequest(
name=name,
developer_email=developer_email,
)
# Make the API call and handle potential errors.
try:
print("Sending RegisterGcp request:")
response = client.register_gcp(request=request)
print("Registered GCP project successfully:")
print(response)
except RuntimeError as e:
print(f"An error occurred: {e}")
if __name__ == "__main__":
# Your Merchant Center account ID.
# This can be found in the Merchant Center UI.
_account_id = configuration.Configuration().read_merchant_info()
# The developer email to associate with the GCP project.
_developer_email = "YOUR_EMAIL_HERE"
register_gcp(_account_id, _developer_email)
জাভা
নমুনাগুলি ডাউনলোড করুন এবং জাভা ক্লায়েন্ট লাইব্রেরি সেট আপ করতে Google Merchant API Java Samples থেকে নির্দেশিকা অনুসরণ করুন।
import com.google.api.gax.core.FixedCredentialsProvider;
import com.google.auth.oauth2.GoogleCredentials;
import com.google.shopping.merchant.accounts.v1.DeveloperRegistration;
import com.google.shopping.merchant.accounts.v1.DeveloperRegistrationName;
import com.google.shopping.merchant.accounts.v1.DeveloperRegistrationServiceClient;
import com.google.shopping.merchant.accounts.v1.DeveloperRegistrationServiceSettings;
import com.google.shopping.merchant.accounts.v1.RegisterGcpRequest;
import shopping.merchant.samples.utils.Authenticator;
import shopping.merchant.samples.utils.Config;
/**
* This class demonstrates how to register the GCP project used to call the Merchant API with a
* developer email.
*/
public class RegisterGcpSample {
public static void registerGcp(Config config, String developerEmail) throws Exception {
// Obtains OAuth token based on the user's configuration.
GoogleCredentials credential = new Authenticator().authenticate();
// Creates service settings using the credentials retrieved above.
DeveloperRegistrationServiceSettings developerRegistrationServiceSettings =
DeveloperRegistrationServiceSettings.newBuilder()
.setCredentialsProvider(FixedCredentialsProvider.create(credential))
.build();
// Creates DeveloperRegistration name to identify the DeveloperRegistration.
// The name has the format: accounts/{account}/developerRegistration
String name =
DeveloperRegistrationName.newBuilder()
.setAccount(config.getAccountId().toString())
.build()
.toString();
// Calls the API and catches and prints any network failures/errors.
try (DeveloperRegistrationServiceClient developerRegistrationServiceClient =
DeveloperRegistrationServiceClient.create(developerRegistrationServiceSettings)) {
// Creates a request to register the GCP project with the developer email.
RegisterGcpRequest request =
RegisterGcpRequest.newBuilder().setName(name).setDeveloperEmail(developerEmail).build();
System.out.println("Sending RegisterGcp request:");
DeveloperRegistration response = developerRegistrationServiceClient.registerGcp(request);
System.out.println(response);
} catch (Exception e) {
System.out.println(e);
}
}
public static void main(String[] args) throws Exception {
Config config = Config.load();
String developerEmail = "YOUR_EMAIL_HERE"; // Replace with your email
registerGcp(config, developerEmail);
}
}
পিএইচপি
নমুনাগুলি ডাউনলোড করুন এবং php ক্লায়েন্ট লাইব্রেরি সেট আপ করতে Google Merchant API PHP Samples থেকে নির্দেশিকা অনুসরণ করুন।
require_once __DIR__ . '/../../../../vendor/autoload.php';
require_once __DIR__ . '/../../../Authentication/Authentication.php';
require_once __DIR__ . '/../../../Authentication/Config.php';
use Google\ApiCore\ApiException;
use Google\Shopping\Merchant\Accounts\V1\Client\DeveloperRegistrationServiceClient;
use Google\Shopping\Merchant\Accounts\V1\RegisterGcpRequest;
/**
* This class demonstrates how to register the GCP project used to call the
* Merchant API with a developer email.
*/
class RegisterGcpSample
{
/**
* A helper function to create the name string for the
* DeveloperRegistration.
*
* @param string $accountId The merchant account ID.
* @return string The name, which has the format:
* `accounts/{account}/developerRegistration`
*/
private static function getName(string $accountId): string
{
return sprintf("accounts/%s/developerRegistration", $accountId);
}
/**
* Registers the GCP project with a developer email.
*
* @param array $config The configuration data for authentication and account ID.
* @param string $developerEmail The email of the developer to register.
*/
public static function registerGcpSample(array $config, string $developerEmail): void
{
// Obtains OAuth credentials from the configuration file.
$credentials = Authentication::useServiceAccountOrTokenFile();
// Creates a configuration object for the client.
$options = ['credentials' => $credentials];
// Creates the DeveloperRegistrationServiceClient.
$developerRegistrationServiceClient = new DeveloperRegistrationServiceClient($options);
// Creates the name of the developer registration to identify it.
$name = self::getName($config['accountId']);
// Calls the API and handles any network failures.
try {
// Creates a request to register the GCP project with the developer email.
$request = new RegisterGcpRequest([
'name' => $name,
'developer_email' => $developerEmail
]);
printf("Sending RegisterGcp request:%s", PHP_EOL);
// The `registerGcp` method returns a `DeveloperRegistration` object
// upon success.
$response = $developerRegistrationServiceClient->registerGcp($request);
print "Successfully registered developer email '$developerEmail' for account {$config['accountId']}.\n";
print_r($response);
} catch (ApiException $e) {
printf("An error occurred: %s%s", $e->getMessage(), PHP_EOL);
}
}
/**
* Helper to execute the sample.
*/
public function callSample(): void
{
$config = Config::generateConfig();
// An email address for a developer to register for the API.
$developerEmail = 'YOUR_EMAIL_HERE'; // Replace with your email
self::registerGcpSample($config, $developerEmail);
}
}
// Executes the sample.
$sample = new RegisterGcpSample();
$sample->callSample();
সিআরএল
curl -X POST "https://merchantapi.googleapis.com/accounts/v1/accounts/{ACCOUNT_ID}/developerRegistration:registerGcp" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer {ACCESS_TOKEN}" \
-d '{
"developerEmail": "{DEVELOPER_EMAIL}"
}'
নিবন্ধনের পর সর্বোত্তম অনুশীলন
শক্তিশালী অ্যাক্সেস ব্যবস্থাপনা থেকে উপকৃত হতে এবং ভবিষ্যতে পরিষেবা ব্যাহত হওয়া রোধ করতে, আমরা আপনাকে প্রাথমিক নিবন্ধন সম্পন্ন করার পরে কিছু সেরা অনুশীলন অনুসরণ করার পরামর্শ দিচ্ছি:
API ডেভেলপারকে অতিরিক্ত অনুমতি দিন
যখন আপনি একজন ডেভেলপার পরিচিতি নিবন্ধন করেন, তখন তাদের স্বয়ংক্রিয়ভাবে API_DEVELOPER ভূমিকা দেওয়া হয়। এই ভূমিকায় মার্চেন্ট সেন্টার অ্যাকাউন্ট পরিচালনা বা সমস্ত API কল করার জন্য প্রয়োজনীয় অন্যান্য অনুমতি অন্তর্ভুক্ত থাকে না। আমরা আপনার ডেভেলপারদের ব্যাপক অ্যাক্সেস প্রদানের জন্য ADMIN বা STANDARD ভূমিকা যোগ করার পরামর্শ দিচ্ছি।
ব্যবহারকারীর অ্যাক্সেস অধিকার পরিবর্তন করতে, accounts.users.patch পদ্ধতিটি ব্যবহার করুন। ভূমিকা যোগ বা অপসারণের জন্য অনুরোধ বডির updateMask ক্ষেত্রে আপনি অ্যাক্সেস অধিকারগুলি নির্দিষ্ট করুন:
PATCH https://merchantapi.googleapis.com/accounts/v1/{ACCOUNT_ID}/users/{DEVELOPER_EMAIL}?update_mask=access_rights
Content-Type: application/json
Authorization: Bearer {ACCESS_TOKEN}"
{
"name": "accounts/{ACCOUNT_ID}/users/{DEVELOPER_EMAIL}",
"access_rights": [ "ADMIN", "API_DEVELOPER" ]
}
পাইথন
from examples.authentication import configuration
from examples.authentication import generate_user_credentials
from google.protobuf import field_mask_pb2
from google.shopping.merchant_accounts_v1 import AccessRight
from google.shopping.merchant_accounts_v1 import UpdateUserRequest
from google.shopping.merchant_accounts_v1 import User
from google.shopping.merchant_accounts_v1 import UserServiceClient
FieldMask = field_mask_pb2.FieldMask
_ACCOUNT = configuration.Configuration().read_merchant_info()
def update_user(user_email, user_access_right):
"""Updates a user to make it an admin of the MC account."""
credentials = generate_user_credentials.main()
client = UserServiceClient(credentials=credentials)
# Create user name string
name = "accounts/" + _ACCOUNT + "/users/" + user_email
user = User(name=name, access_rights=[user_access_right])
field_mask = FieldMask(paths=["access_rights"])
try:
request = UpdateUserRequest(user=user, update_mask=field_mask)
print("Sending Update User request")
response = client.update_user(request=request)
print("Updated User Name below")
print(response.name)
except RuntimeError as e:
print(e)
if __name__ == "__main__":
# Modify this email to update the right user
email = "USER_MAIL_ACCOUNT"
access_right = AccessRight.ADMIN
update_user(email, access_right)
জাভা
import com.google.api.gax.core.FixedCredentialsProvider;
import com.google.auth.oauth2.GoogleCredentials;
import com.google.protobuf.FieldMask;
import com.google.shopping.merchant.accounts.v1.AccessRight;
import com.google.shopping.merchant.accounts.v1.UpdateUserRequest;
import com.google.shopping.merchant.accounts.v1.User;
import com.google.shopping.merchant.accounts.v1.UserName;
import com.google.shopping.merchant.accounts.v1.UserServiceClient;
import com.google.shopping.merchant.accounts.v1.UserServiceSettings;
import shopping.merchant.samples.utils.Authenticator;
import shopping.merchant.samples.utils.Config;
/** This class demonstrates how to update a user to make it an admin of the MC account. */
public class UpdateUserSample {
public static void updateUser(Config config, String email, AccessRight accessRight)
throws Exception {
GoogleCredentials credential = new Authenticator().authenticate();
UserServiceSettings userServiceSettings =
UserServiceSettings.newBuilder()
.setCredentialsProvider(FixedCredentialsProvider.create(credential))
.build();
// Creates user name to identify user.
String name =
UserName.newBuilder()
.setAccount(config.getAccountId().toString())
.setEmail(email)
.build()
.toString();
// Create a user with the updated fields.
User user = User.newBuilder().setName(name).addAccessRights(accessRight).build();
FieldMask fieldMask = FieldMask.newBuilder().addPaths("access_rights").build();
try (UserServiceClient userServiceClient = UserServiceClient.create(userServiceSettings)) {
UpdateUserRequest request =
UpdateUserRequest.newBuilder().setUser(user).setUpdateMask(fieldMask).build();
System.out.println("Sending Update User request");
User response = userServiceClient.updateUser(request);
System.out.println("Updated User Name below");
System.out.println(response.getName());
} catch (Exception e) {
System.out.println(e);
}
}
public static void main(String[] args) throws Exception {
Config config = Config.load();
String email = "testUser@gmail.com";
// Give the user admin rights. Note that all other rights, like
// PERFORMANCE_REPORTING, would be overwritten in this example
// if the user had those access rights before the update.
AccessRight accessRight = AccessRight.ADMIN;
updateUser(config, email, accessRight);
}
}
পিএইচপি
use Google\ApiCore\ApiException;
use Google\Protobuf\FieldMask;
use Google\Shopping\Merchant\Accounts\V1\AccessRight;
use Google\Shopping\Merchant\Accounts\V1\UpdateUserRequest;
use Google\Shopping\Merchant\Accounts\V1\User;
use Google\Shopping\Merchant\Accounts\V1\Client\UserServiceClient;
/**
* Updates a user.
*
* @param array $config The configuration data.
* @param string $email The email address of the user.
* @param int $accessRight The access right to grant the user.
* @return void
*/
function updateUser($config, $email, $accessRights): void
{
// Gets the OAuth credentials to make the request.
$credentials = Authentication::useServiceAccountOrTokenFile();
// Creates options config containing credentials for the client to use.
$options = ['credentials' => $credentials];
// Creates a client.
$userServiceClient = new UserServiceClient($options);
// Creates user name to identify user.
$name = 'accounts/' . $config['accountId'] . "/users/" . $email;
$user = (new User())
->setName($name)
->setAccessRights($accessRights);
$fieldMask = (new FieldMask())->setPaths(['access_rights']);
// Calls the API and catches and prints any network failures/errors.
try {
$request = new UpdateUserRequest([
'user' => $user,
'update_mask' => $fieldMask,
]);
print "Sending Update User request\n";
$response = $userServiceClient->updateUser($request);
print "Updated User Name below\n";
print $response->getName() . "\n";
} catch (ApiException $e) {
print $e->getMessage();
}
}
$config = Config::generateConfig();
$email = "testUser@gmail.com";
$accessRights = [AccessRight::ADMIN];
updateUser($config, $email, $accessRights);
সিআরএল
curl -X PATCH \
"https://merchantapi.googleapis.com/accounts/v1/{ACCOUNT_ID}/users/{USER_EMAIL}?update_mask=access_rights" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer {ACCESS_TOKEN}" \
-d '{
"access_rights": [
"ADMIN",
"API_DEVELOPER"
]
}'
আরও ডেভেলপার পরিচিতি যোগ করুন
প্রাথমিক ডেভেলপার পরিচিতি যদি অ্যাক্সেস ছেড়ে দেয় বা হারিয়ে ফেলে, তাহলে ব্যবসায়িক ব্যাঘাত এড়াতে, অপ্রয়োজনীয় পরিচিতি থাকা অত্যন্ত গুরুত্বপূর্ণ। আমরা সুপারিশ করছি যে ব্যাকআপ হিসেবে Merchant Center-এ API_DEVELOPER ভূমিকা সহ কমপক্ষে একজন অতিরিক্ত ব্যবহারকারীকে রাখা হোক।
আপনি Merchant API-তে accounts.users পরিষেবা অথবা Merchant Center UI-তে Access and services পৃষ্ঠা ব্যবহার করে একজন ব্যবহারকারী যোগ করতে পারেন অথবা বিদ্যমান ব্যবহারকারী আপডেট করতে পারেন। সক্রিয়ভাবে ব্যাকআপ ডেভেলপারদের যোগ করার মাধ্যমে, আপনি একটি আরও স্থিতিস্থাপক ইন্টিগ্রেশন তৈরি করেন যা একক ব্যক্তির উপর নির্ভরশীল নয়।
PATCH https://merchantapi.googleapis.com/products/v1/accounts/{ACCOUNT_ID}/users
Content-Type: application/json
Authorization: Bearer {ACCESS_TOKEN}"
{
"user_id": {USER_EMAIL},
"user": { "access_rights": [ "API_DEVELOPER", "ADMIN" ] }
}
পাইথন
from examples.authentication import configuration
from examples.authentication import generate_user_credentials
from google.shopping.merchant_accounts_v1 import AccessRight
from google.shopping.merchant_accounts_v1 import CreateUserRequest
from google.shopping.merchant_accounts_v1 import User
from google.shopping.merchant_accounts_v1 import UserServiceClient
_ACCOUNT = configuration.Configuration().read_merchant_info()
def get_parent(account_id):
return f"accounts/{account_id}"
def create_user(user_email):
"""Creates a user for a Merchant Center account."""
# Get OAuth credentials
credentials = generate_user_credentials.main()
# Create a UserServiceClient
client = UserServiceClient(credentials=credentials)
# Create parent string
parent = get_parent(_ACCOUNT)
# Create the request
request = CreateUserRequest(
parent=parent,
user_id=user_email,
user=User(
access_rights=[AccessRight.ADMIN, AccessRight.PERFORMANCE_REPORTING]
),
)
try:
print("Sending Create User request")
response = client.create_user(request=request)
print("Inserted User Name below")
print(response.name)
except RuntimeError as e:
print(e)
if __name__ == "__main__":
# Modify this email to create a new user
email = "USER_MAIL_ACCOUNT"
create_user(email)
জাভা
import com.google.api.gax.core.FixedCredentialsProvider;
import com.google.auth.oauth2.GoogleCredentials;
import com.google.shopping.merchant.accounts.v1.AccessRight;
import com.google.shopping.merchant.accounts.v1.CreateUserRequest;
import com.google.shopping.merchant.accounts.v1.User;
import com.google.shopping.merchant.accounts.v1.UserServiceClient;
import com.google.shopping.merchant.accounts.v1.UserServiceSettings;
import shopping.merchant.samples.utils.Authenticator;
import shopping.merchant.samples.utils.Config;
/** This class demonstrates how to create a user for a Merchant Center account. */
public class CreateUserSample {
private static String getParent(String accountId) {
return String.format("accounts/%s", accountId);
}
public static void createUser(Config config, String email) throws Exception {
// Obtains OAuth token based on the user's configuration.
GoogleCredentials credential = new Authenticator().authenticate();
// Creates service settings using the credentials retrieved above.
UserServiceSettings userServiceSettings =
UserServiceSettings.newBuilder()
.setCredentialsProvider(FixedCredentialsProvider.create(credential))
.build();
// Creates parent to identify where to insert the user.
String parent = getParent(config.getAccountId().toString());
// Calls the API and catches and prints any network failures/errors.
try (UserServiceClient userServiceClient = UserServiceClient.create(userServiceSettings)) {
CreateUserRequest request =
CreateUserRequest.newBuilder()
.setParent(parent)
// This field is the email address of the user.
.setUserId(email)
.setUser(
User.newBuilder()
.addAccessRights(AccessRight.ADMIN)
.addAccessRights(AccessRight.PERFORMANCE_REPORTING)
.build())
.build();
System.out.println("Sending Create User request");
User response = userServiceClient.createUser(request);
System.out.println("Inserted User Name below");
// The last part of the user name will be the email address of the user.
// Format: `accounts/{account}/user/{user}`
System.out.println(response.getName());
} catch (Exception e) {
System.out.println(e);
}
}
public static void main(String[] args) throws Exception {
Config config = Config.load();
// The email address of this user.
String email = "testUser@gmail.com";
createUser(config, email);
}
}
পিএইচপি
use Google\ApiCore\ApiException;
use Google\Shopping\Merchant\Accounts\V1\AccessRight;
use Google\Shopping\Merchant\Accounts\V1\CreateUserRequest;
use Google\Shopping\Merchant\Accounts\V1\User;
use Google\Shopping\Merchant\Accounts\V1\Client\UserServiceClient;
/**
* Creates a user.
*
* @param array $config The configuration data.
* @param string $email The email address of the user.
* @return void
*/
function createUser($config, $email): void
{
// Gets the OAuth credentials to make the request.
$credentials = Authentication::useServiceAccountOrTokenFile();
// Creates options config containing credentials for the client to use.
$options = ['credentials' => $credentials];
// Creates a client.
$userServiceClient = new UserServiceClient($options);
// Creates parent to identify where to insert the user.
$parent = sprintf("accounts/%s", $config['accountId']);
// Calls the API and catches and prints any network failures/errors.
try {
$request = new CreateUserRequest([
'parent' => $parent,
'user_id' => $email,
'user' => (new User())
->setAccessRights([AccessRight::ADMIN,AccessRight::PERFORMANCE_REPORTING])
]);
print "Sending Create User request\n";
$response = $userServiceClient->createUser($request);
print "Inserted User Name below\n";
print $response->getName() . "\n";
} catch (ApiException $e) {
print $e->getMessage();
}
}
$config = Config::generateConfig();
$email = "testUser@gmail.com";
createUser($config, $email);
সিআরএল
curl -X PATCH \
"https://merchantapi.googleapis.com/products/v1/accounts/{ACCOUNT_ID}/users/{USER_EMAIL}?update_mask=access_rights" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer {ACCESS_TOKEN}" \
-d '{
"access_rights": [
"ADMIN",
"API_DEVELOPER"
]
}'