میتوانید از «میانای برنامهسازی کاربردی بازرگان» برای ایجاد حسابهای Merchant Center استفاده کنید، که میتوانند بااستفاده از accountAggregation، accountManagement، یا comparisonShopping به حساب پیشرفته پیوند داده شوند. روش
accounts.createAndConfigure
به شما امکان میدهد حسابی ایجاد کنید و درصورت تمایل آن را با کاربران پیکربندی کنید و
آن را ازطریق سرویسها به حسابهای دیگر پیوند دهید.
این راهنما توضیح میدهد که چگونه از «میانای برنامهسازی کاربردی بازرگان» برای ایجاد حسابها
بااستفاده از سرویسهایی مثل accountManagement،
comparisonShopping، یا accountAggregation استفاده کنید. هنگام استفاده از
accounts.createAndConfigure، باید حساب جدید را با مشخص کردن حداقل یکی از accountAggregation، accountManagement، یا
comparisonShopping در فیلد service به یک ارائهدهنده پیوند دهید.
میتوانید accountAggregation و comparisonShopping را در یک درخواست مشخص کنید، اما accountManagement را نمیتوان با accountAggregation یا comparisonShopping ترکیب کرد.
اگر accountManagement را مشخص کنید، باید حداقل یک کاربر را نیز بااستفاده از فیلد user یا users به حساب جدید اضافه کنید.
پیشنیازها
قبلاز اینکه بتوانید بااستفاده از Merchant API حساب ایجاد کنید، مطمئن شوید که الزامات زیر را بسته به خدماتی که استفاده میکنید برآورده میکنید:
- دسترسی سرپرست: هنگام پیوند دادن حساب جدید بااستفاده از
accountManagement،comparisonShopping، یاaccountAggregation، باید به حساب ارائهدهنده دسترسی سرپرست داشته باشید. - حساب پیشرفته: اگر از
accountAggregationاستفاده میکنید، حساب ارائهدهنده شما باید حساب پیشرفتهای باشد که برای تجمیع حساب پیکربندی شده است. اگر ارائهدهنده خدمات هستید و نیاز دارید حساب پیشرفتهای راهاندازی کنید، برای دریافت کمک در پیکربندی، با پشتیبانی تماس بگیرید.
ایجاد حساب (بااستفاده از مدیریت حساب یا خرید مقایسهای)
برای ایجاد حساب جدید، با
accounts.createAndConfigure تماس بگیرید.
این رویکرد برای شرکایی که به فروشندگان در مدیریت حسابهایشان کمک میکنند توصیه میشود، زیرا به فروشندگان امکان میدهد کنترل کامل و مالکیت حساب خود را حفظ کنند و درعینحال اجازههای خاصی را به شرکا اعطا کنند.
در متن درخواست:
- جزئیات حسابی را که میخواهید ایجاد کنید در
accountفیلد ارائه دهید. - در فیلد
accountName، از نشانههای سجاوندی تکراری و غیرضروری، حروف بزرگ، زیرخط، همه حروف بزرگ، اموجی، یا نمادهای غیرحرفیعددی مثل/یا_استفاده نکنید. از پسوندهای کسبوکار (مثل «شرکت» یا «GmbH»)، نوشتار تبلیغاتی، اطلاعات شخصی، یا زبان نامناسب اجتناب کنید. از نامی کوتاه، واضح، و حرفهای استفاده کنید. برای اطلاعات بیشتر، به افزودن نام کسبوکار مراجعه کنید. - اگر از
accountManagementاستفاده میکنید، حداقل یک کاربر را در فیلدuserمشخص کنید که به حساب دسترسی داشته باشد. - در فیلد
service، هر سرویسی را که میخواهید به این حساب ارائه دهید مشخص کنید، برای مثالaccountManagement، وproviderرا روی نام منبع حساب خود تنظیم کنید (برای مثال،providers/{YOUR_ACCOUNT_ID}). برای فهرستی از سرویسهای دردسترس مثلproductsManagementیاcampaignsManagement، به مدیریت روابط حساب مراجعه کنید.
در اینجا نمونهای از درخواست ایجاد حسابی بهنام «merchantStore»
و پیوند دادن آن به حساب {YOUR_ACCOUNT_ID} برای
مدیریت حساب و محصول آمده است:
POST https://merchantapi.googleapis.com/accounts/v1/accounts:createAndConfigure
{
"account": {
"accountName": "merchantStore",
"adultContent": false,
"timeZone": {
"id": "America/New_York"
},
"languageCode": "en-US"
},
"user": [
{
"userId": "test@example.com",
"user": {
"accessRights": ["ADMIN"]
}
}
],
"service": [
{
"accountManagement": {},
"provider": "providers/{YOUR_ACCOUNT_ID}"
},
{
"productsManagement": {},
"provider": "providers/{YOUR_ACCOUNT_ID}"
}
]
}
تماس موفقیتآمیز حساب جدیدی ایجاد میکند و آن را به حساب شما برای خدمات مشخصشده پیوند میدهد. اگر سرویسهای accountManagement، accountAggregation،
یا comparisonShopping را درطول ایجاد مشخص کنید، این سرویسها بهطور خودکار
تأیید میشوند و وضعیت پیوند ESTABLISHED است. پیوندهای سرویس دیگر ممکن است تا زمانی که حساب ایجادشده آنها را نپذیرد در وضعیت PENDING باشند. بدنه پاسخ
حاوی منبع
Account جدیداً ایجادشده است.
نمونه زیر نحوه استفاده از
accounts.createAndConfigure
برای ایجاد و پیکربندی حساب را نشان میدهد:
جاوا
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.Account;
import com.google.shopping.merchant.accounts.v1.AccountManagement;
import com.google.shopping.merchant.accounts.v1.AccountsServiceClient;
import com.google.shopping.merchant.accounts.v1.AccountsServiceSettings;
import com.google.shopping.merchant.accounts.v1.CreateAndConfigureAccountRequest;
import com.google.shopping.merchant.accounts.v1.CreateAndConfigureAccountRequest.AddAccountService;
import com.google.shopping.merchant.accounts.v1.CreateAndConfigureAccountRequest.AddUser;
import com.google.shopping.merchant.accounts.v1.ProductsManagement;
import com.google.shopping.merchant.accounts.v1.User;
import com.google.type.TimeZone;
import java.util.List;
import shopping.merchant.samples.utils.Authenticator;
/**
* This class demonstrates how to create a new Merchant Center account and configure it with various
* services.
*/
public class CreateAndConfigureAccountSample {
public static void createAndConfigureAccount(
long providerId, String newAccountName, String userEmail) throws Exception {
// Obtains OAuth token based on the user's configuration.
GoogleCredentials credential = new Authenticator().authenticate();
// Creates service settings using the credentials retrieved above.
AccountsServiceSettings accountsServiceSettings =
AccountsServiceSettings.newBuilder()
.setCredentialsProvider(FixedCredentialsProvider.create(credential))
.build();
// Calls the API and catches and prints any network failures/errors.
try (AccountsServiceClient accountsServiceClient =
AccountsServiceClient.create(accountsServiceSettings)) {
// The account to be created.
Account account =
Account.newBuilder()
.setAccountName(newAccountName)
.setTimeZone(TimeZone.newBuilder().setId("Europe/Zurich").build())
.setLanguageCode("en-US")
.build();
// The services to be added to the new account.
// This sample shows how to configure a new account with account management and
// product management.
// For more information about the different services, see:
// https://developers.google.com/merchant/api/guides/accounts/services
AddAccountService accountManagementService =
AddAccountService.newBuilder()
.setProvider("accounts/" + providerId)
.setExternalAccountId("external_account_id")
.setAccountManagement(AccountManagement.newBuilder().build())
.build();
// This part is optional. You can also omit this and link the account later.
AddAccountService productsManagementService =
AddAccountService.newBuilder()
.setProvider("accounts/" + providerId)
.setExternalAccountId("external_account_id")
.setProductsManagement(ProductsManagement.newBuilder().build())
.build();
// For sub-account creation, use the AccountAggregation service. For an example on how to do
// this, see the `CreateSubAccount` sample.
// The user to be added to the new account.
// This part is optional.
AddUser user =
AddUser.newBuilder()
.setUserId(userEmail)
.setUser(User.newBuilder().addAccessRights(AccessRight.STANDARD).build())
.build();
CreateAndConfigureAccountRequest request =
CreateAndConfigureAccountRequest.newBuilder()
.setAccount(account)
.addAllService(List.of(accountManagementService, productsManagementService))
.addUser(user)
.build();
System.out.println("Sending Create and Configure Account request:");
Account response = accountsServiceClient.createAndConfigureAccount(request);
System.out.println("Created Account below");
System.out.println(response);
} catch (Exception e) {
System.out.println(e);
}
}
public static void main(String[] args) throws Exception {
// This is the provider ID of the e-commerce platform.
long providerId = 123L;
// This is the name of the new account to be created.
String newAccountName = "MyNewShop";
// This is the email of a user to be added to the new account.
String userEmail = "test-user@gmail.com";
createAndConfigureAccount(providerId, newAccountName, userEmail);
}
}
پساز ایجاد چنین حسابی، باید با انجام مراحلی مانند پذیرفتن «شرایط خدمات» ، راهاندازی اطلاعات کسبوکار، و درستیسنجی وبسایت، آن را آماده کنید.
درستیسنجی ایمیل را درطول ایجاد حساب غیرفعال کنید
هنگام ایجاد حساب با accounts.createAndConfigure، میتوانید بهصورت اختیاری
ایمیلهای درستیسنجی را برای کاربران جدیدی که بااستفاده از فیلد user اضافه شدهاند با
تنظیم verificationMailSettings.verificationMailMode روی
SUPPRESS_VERIFICATION_MAIL در درخواست آن کاربر غیرفعال کنید. اگر قصد دارید کاربران را بلافاصله پساز ایجاد ازطرف فروشنده بااستفاده از روش
users.verifySelf
درستیسنجی کنید، این مفید است. بهطور پیشفرض، verificationMailMode روی SEND_VERIFICATION_MAIL تنظیم شده است، و
ایمیلهای درستیسنجی برای کاربران جدیدی که درطول ایجاد حساب اضافه میشوند ارسال میشود.
POST https://merchantapi.googleapis.com/accounts/v1/accounts:createAndConfigure
{
"account": {
"accountName": "merchantStore",
"adultContent": false,
"timeZone": {
"id": "America/New_York"
},
"languageCode": "en-US"
},
"user": [
{
"userId": "test@example.com",
"user": {
"accessRights": ["ADMIN"]
},
"verificationMailSettings": {
"verificationMailMode": "SUPPRESS_VERIFICATION_MAIL"
}
}
],
"service": [
{
"accountManagement": {},
"provider": "providers/{YOUR_ACCOUNT_ID}"
}
]
}
اگر verificationMailMode را روی SUPPRESS_VERIFICATION_MAIL تنظیم کنید، باید
برای هر کاربری که درطول ایجاد اضافه میشود با users.verifySelf تماس بگیرید تا
درستیسنجی را تکمیل کنید. این تماس باید بهعنوان کاربر درستیسنجیشده اصالتسنجی شود
(کاربر مشخصشده در userId)، برای مثال بااستفاده از کد OAuth از
کاربر.
درطول ایجاد حساب، نام مستعار مشخص کنید
میتوانید نام مستعاری برای حساب در زمینه ارائهدهنده در
CreateAndConfigureAccountRequest بااستفاده از فیلد setAlias مشخص کنید. از نام مستعار میتوان برای شناسایی حساب در سیستم شما استفاده کرد. اگر ارائهدهنده خدمات هستید، میتوانید از نام مستعار برای بازیابی حساب بااستفاده از GET /accounts/v1/accounts/{provider}~{alias} استفاده کنید. نام مستعار باید برای یک
ارائهدهنده معین منحصربهفرد باشد و باید سرویسی با همان ارائهدهنده را در فیلد
service درخواست مشخص کنید. برای اطلاعات بیشتر درباره الزامات نام مستعار،
به مدیریت روابط حساب مراجعه کنید.
POST https://merchantapi.googleapis.com/accounts/v1/accounts:createAndConfigure
{
"account": {
"accountName": "merchantStore",
"adultContent": false,
"timeZone": {
"id": "America/New_York"
},
"languageCode": "en-US"
},
"service": [
{
"accountManagement": {},
"provider": "providers/{YOUR_ACCOUNT_ID}"
}
],
"setAlias": [
{
"provider": "providers/{YOUR_ACCOUNT_ID}",
"accountIdAlias": "my-merchant-alias"
}
]
}
جریان آمادهسازی توصیهشده
اگر شریکی هستید که حسابی را به نمایندگی از یک فروشنده ایجاد میکنید، جریان زیر را توصیه میکنیم:
- ایجاد حساب: با اطلاعات اعتباری شریک خود با
accounts.createAndConfigureتماس بگیرید تا حساب جدیدی ایجاد کنید.-
serviceرا تنظیم کنید تا شاملaccountManagementپیوند به شناسه ارائهدهنده شما شود. - فروشنده را بااستفاده از فیلد
userبهعنوان کاربر اضافه کنید وverificationMailSettings.verificationMailModeرا رویSUPPRESS_VERIFICATION_MAILتنظیم کنید.
-
- درستیسنجی کاربر: با اعتبارنامههای فروشنده (برای مثال، بااستفاده از
یک کد OAuth)،
users.verifySelfرا فراخوانی کنید تا وضعیت کاربر ازPENDINGبهVERIFIEDتغییر کند. - تنظیم کشور کسبوکار: با اطلاعات اعتباری فروشنده، کشور کسبوکار را با بهروزرسانی
address.regionCodeبااستفاده ازaccounts.updateBusinessInfoتنظیم کنید. این کار قبلاز پذیرفتن «شرایط خدمات» الزامی است . - پذیرفتن «شرایط خدمات» : با اطلاعات اعتباری فروشنده، «شرایط خدمات» را بپذیرید .
این جریان به فروشنده امکان میدهد بدون دریافت ایمیلهای دعوت از Google، بهطور یکپارچه در پلاتفرم شما ثبت شود.
ایجاد حساب مشتری (بااستفاده از تجمیع حساب)
حسابهای مشتری حسابهای Merchant Center متمایزی هستند که بااستفاده از سرویس accountAggregation به حساب پیشرفته شما پیوند شدهاند و امکان مدیریت متمرکز را درحالیکه تنظیمات، وبسایتها، و فیدهای داده جداگانه را حفظ میکنند فراهم میکنند. میتوانید از زیر API «حسابهای Merchant» برای ایجاد حسابهای مشتری جدید استفاده کنید.
برای ایجاد حسابهای مشتری، ابتدا باید راهاندازی حساب پیشرفته داشته باشید. برای تبدیل حساب Merchant Center خود به حساب پیشرفته، باید سرپرست حساب باشید و حسابتان نباید هیچ مشکل معلقی داشته باشد.
برای ایجاد حساب مشتری جدید، با
accounts.createAndConfigure تماس بگیرید.
در متن درخواست:
- جزئیات حسابی را که میخواهید ایجاد کنید در
accountفیلد ارائه دهید. - در فیلد
accountName، از نشانههای سجاوندی تکراری و غیرضروری، حروف بزرگ، زیرخط، یا نمادهای غیرحرفیعددی (مثل «/» یا «_») استفاده نکنید. از پسوندهای کسبوکار (مثل «شرکت» یا «GmbH»)، نوشتار تبلیغاتی، اطلاعات شخصی، یا زبان نامناسب استفاده نکنید. از نامی کوتاه، واضح، و حرفهای استفاده کنید. برای اطلاعات بیشتر، به افزودن نام کسبوکار مراجعه کنید. - بهصورت اختیاری، هر کاربر مجاز جدیدی را در فیلد
userمشخص کنید. دسترسی کاربر به حساب نیز از حساب پیشرفته والد به ارث میرسد. - در فیلد
service،accountAggregationرا مشخص کنید وproviderرا روی نام منبع حساب پیشرفتهتان (برای نمونه،providers/{ADVANCED_ACCOUNT_ID}) تنظیم کنید. این کار حساب پیشرفتهتان را بهعنوان تجمیعکننده حساب جدید تعیین میکند.
در اینجا نمونهای از درخواست ایجاد حساب مشتری بهنام «merchantStore»
پیوندشده به حساب پیشرفته
{ADVANCED_ACCOUNT_ID} آمده است:
POST https://merchantapi.googleapis.com/accounts/v1/accounts:createAndConfigure
{
"account": {
"accountName": "merchantStore",
"adultContent": false,
"timeZone": {
"id": "America/New_York"
},
"languageCode": "en-US"
},
"service": [
{
"accountAggregation": {},
"provider": "providers/{ADVANCED_ACCOUNT_ID}"
}
]
}
تماس موفق حساب مشتری جدیدی ایجاد میکند و آن را به حساب پیشرفته مشخصشده شما پیوند میدهد. بدنه پاسخ حاوی منبع Account تازه ایجادشده خواهد بود.
نمونههای زیر نشان میدهد که چگونه از
accounts.createAndConfigure برای ایجاد
حساب مشتری جدید استفاده کنید.
جاوا
import com.google.api.gax.core.FixedCredentialsProvider;
import com.google.auth.oauth2.GoogleCredentials;
import com.google.shopping.merchant.accounts.v1.Account;
import com.google.shopping.merchant.accounts.v1.AccountAggregation;
import com.google.shopping.merchant.accounts.v1.AccountsServiceClient;
import com.google.shopping.merchant.accounts.v1.AccountsServiceSettings;
import com.google.shopping.merchant.accounts.v1.CreateAndConfigureAccountRequest;
import com.google.shopping.merchant.accounts.v1.CreateAndConfigureAccountRequest.AddAccountService;
import com.google.type.TimeZone;
import shopping.merchant.samples.utils.Authenticator;
import shopping.merchant.samples.utils.Config;
/** This class demonstrates how to create a sub-account under an advanced account. */
public class CreateSubAccountSample {
private static String getParent(String accountId) {
return String.format("accounts/%s", accountId);
}
public static Account createSubAccount(Config config) throws Exception {
// Obtains OAuth token based on the user's configuration.
GoogleCredentials credential = new Authenticator().authenticate();
// Creates service settings using the credentials retrieved above.
AccountsServiceSettings accountsServiceSettings =
AccountsServiceSettings.newBuilder()
.setCredentialsProvider(FixedCredentialsProvider.create(credential))
.build();
// Creates parent/provider to identify the advanced account into which to insert the subaccount.
String parent = getParent(config.getAccountId().toString());
// Calls the API and catches and prints any network failures/errors.
try (AccountsServiceClient accountsServiceClient =
AccountsServiceClient.create(accountsServiceSettings)) {
CreateAndConfigureAccountRequest request =
CreateAndConfigureAccountRequest.newBuilder()
.setAccount(
Account.newBuilder()
.setAccountName("Demo Business")
.setAdultContent(false)
.setTimeZone(TimeZone.newBuilder().setId("America/New_York").build())
.setLanguageCode("en-US")
.build())
.addService(
AddAccountService.newBuilder()
.setProvider(parent)
.setAccountAggregation(AccountAggregation.getDefaultInstance())
.build())
.build();
System.out.println("Sending Create SubAccount request");
Account response = accountsServiceClient.createAndConfigureAccount(request);
System.out.println("Inserted Account Name below");
// Format: `accounts/{account}`
System.out.println(response.getName());
return response;
}
}
public static void main(String[] args) throws Exception {
Config config = Config.load();
createSubAccount(config);
}
}
PHP
use Google\ApiCore\ApiException;
use Google\Shopping\Merchant\Accounts\V1\Account;
use Google\Shopping\Merchant\Accounts\V1\AccountAggregation;
use Google\Shopping\Merchant\Accounts\V1\Client\AccountsServiceClient;
use Google\Shopping\Merchant\Accounts\V1\CreateAndConfigureAccountRequest;
use Google\Shopping\Merchant\Accounts\V1\CreateAndConfigureAccountRequest\AddAccountService;
use Google\Type\TimeZone;
/**
* This class demonstrates how to create a sub-account under an MCA account.
*/
class CreateSubAccount
{
private static function getParent(string $accountId): string
{
return sprintf("accounts/%s", $accountId);
}
public static function createSubAccount(array $config): 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.
$accountsServiceClient = new AccountsServiceClient($options);
// Creates parent/provider to identify the MCA account into which to insert the subaccount.
$parent = self::getParent($config['accountId']);
// Calls the API and catches and prints any network failures/errors.
try {
$request = new CreateAndConfigureAccountRequest([
'account' => (new Account([
'account_name' => 'Demo Business',
'adult_content' => false,
'time_zone' => (new TimeZone(['id' => 'America/New_York'])),
'language_code' => 'en-US',
])),
'service' => [
(new AddAccountService([
'provider' => $parent,
'account_aggregation' => new AccountAggregation,
])),
],
]);
print "Sending Create SubAccount request\n";
$response = $accountsServiceClient->createAndConfigureAccount($request);
print "Inserted Account Name below\n";
// Format: `accounts/{account}
print $response->getName() . PHP_EOL;
} catch (ApiException $e) {
print $e->getMessage();
}
}
public function callSample(): void
{
$config = Config::generateConfig();
self::createSubAccount($config);
}
}
$sample = new CreateSubAccount();
$sample->callSample();
Python
from examples.authentication import configuration
from examples.authentication import generate_user_credentials
from google.shopping.merchant_accounts_v1 import Account
from google.shopping.merchant_accounts_v1 import AccountAggregation
from google.shopping.merchant_accounts_v1 import AccountsServiceClient
from google.shopping.merchant_accounts_v1 import CreateAndConfigureAccountRequest
_ACCOUNT = configuration.Configuration().read_merchant_info()
def get_parent(account_id):
return f"accounts/{account_id}"
def create_sub_account():
"""Creates a sub-account under an advanced account."""
# Get OAuth credentials.
credentials = generate_user_credentials.main()
# Create a client.
client = AccountsServiceClient(credentials=credentials)
# Get the parent advanced account ID.
parent = get_parent(_ACCOUNT)
# Create the request.
request = CreateAndConfigureAccountRequest(
account=Account(
account_name="Demo Business",
adult_content=False,
time_zone={"id": "America/New_York"},
language_code="en-US",
),
service=[
CreateAndConfigureAccountRequest.AddAccountService(
provider=parent,
account_aggregation=AccountAggregation(),
)
],
)
# Make the request and print the response.
try:
print("Sending Create SubAccount request")
response = client.create_and_configure_account(request=request)
print("Inserted Account Name below")
print(response.name)
except RuntimeError as e:
print(e)
if __name__ == "__main__":
create_sub_account()
cURL
curl -X POST \
"https://merchantapi.googleapis.com/accounts/v1/accounts:createAndConfigure" \
-H "Authorization: Bearer {YOUR_ACCESS_TOKEN}" \
-H "Content-Type: application/json" \
-d '{
"account": {
"accountName": "Demo Business",
"adultContent": false,
"timeZone": {
"id": "America/New_York"
},
"languageCode": "en-US"
},
"service": [
{
"accountAggregation": {},
"provider": "providers/{ADVANCED_ACCOUNT_ID}"
}
]
}'
بازیابی حسابهای مشتری
برای فهرست کردن همه حسابهای مشتری یک حساب پیشرفته معین، از روش
accounts.listSubaccounts
استفاده کنید. شناسه حساب پیشرفتهتان را در فیلد provider نشانی وب درخواست ارائه دهید.
در اینجا یک درخواست نمونه آورده شده است:
GET https://merchantapi.googleapis.com/accounts/v1/accounts/{ADVANCED_ACCOUNT_ID}:listSubaccounts
در اینجا نمونهای از پاسخ یک تماس موفق آورده شده است:
{
"accounts": [
{
"name": "accounts/<var class=\"readonly\">{SUB_ACCOUNT_ID_1}</var>",
"accountId": "<var class=\"readonly\">{SUB_ACCOUNT_ID_1}</var>",
"accountName": "<var class=\"readonly\">{SUB_ACCOUNT_NAME_1}</var>",
"timeZone": {
"id": "America/Los_Angeles"
},
"languageCode": "en-US"
},
{
"name": "accounts/<var class=\"readonly\">{SUB_ACCOUNT_ID_2}</var>",
"accountId": "<var class=\"readonly\">{SUB_ACCOUNT_ID_2}</var>",
"accountName": "<var class=\"readonly\">{SUB_ACCOUNT_NAME_2}</var>",
"timeZone": {
"id": "America/Los_Angeles"
},
"languageCode": "en-US"
}
]
}
نمونههای زیر نشان میدهد که چگونه همه حسابهای مشتری حساب پیشرفتهتان را فهرست کنید.
جاوا
import com.google.api.gax.core.FixedCredentialsProvider;
import com.google.auth.oauth2.GoogleCredentials;
import com.google.shopping.merchant.accounts.v1.Account;
import com.google.shopping.merchant.accounts.v1.AccountsServiceClient;
import com.google.shopping.merchant.accounts.v1.AccountsServiceClient.ListSubAccountsPagedResponse;
import com.google.shopping.merchant.accounts.v1.AccountsServiceSettings;
import com.google.shopping.merchant.accounts.v1.ListSubAccountsRequest;
import shopping.merchant.samples.utils.Authenticator;
import shopping.merchant.samples.utils.Config;
/** This class demonstrates how to list all the subaccounts of an advanced account. */
public class ListSubAccountsSample {
private static String getParent(String accountId) {
return String.format("accounts/%s", accountId);
}
public static ListSubAccountsPagedResponse listSubAccounts(Config config) throws Exception {
// Obtains OAuth token based on the user's configuration.
GoogleCredentials credential = new Authenticator().authenticate();
// Creates service settings using the credentials retrieved above.
AccountsServiceSettings accountsServiceSettings =
AccountsServiceSettings.newBuilder()
.setCredentialsProvider(FixedCredentialsProvider.create(credential))
.build();
// Creates parent/provider to identify the advanced account from which to list all sub-accounts.
String parent = getParent(config.getAccountId().toString());
// Calls the API and catches and prints any network failures/errors.
try (AccountsServiceClient accountsServiceClient =
AccountsServiceClient.create(accountsServiceSettings)) {
// The parent has the format: accounts/{account}
ListSubAccountsRequest request =
ListSubAccountsRequest.newBuilder().setProvider(parent).build();
System.out.println("Sending list subaccounts request:");
ListSubAccountsPagedResponse response = accountsServiceClient.listSubAccounts(request);
int count = 0;
// Iterates over all rows in all pages and prints the datasource in each row.
// Automatically uses the `nextPageToken` if returned to fetch all pages of data.
for (Account account : response.iterateAll()) {
System.out.println(account);
count++;
}
System.out.print("The following count of accounts were returned: ");
System.out.println(count);
return response;
}
}
public static void main(String[] args) throws Exception {
Config config = Config.load();
listSubAccounts(config);
}
}
PHP
use Google\ApiCore\ApiException;
use Google\Shopping\Merchant\Accounts\V1\Client\AccountsServiceClient;
use Google\Shopping\Merchant\Accounts\V1\ListSubAccountsRequest;
/**
* This class demonstrates how to list all the subaccounts of an advanced account.
*/
class ListSubAccounts
{
private static function getParent(string $accountId): string
{
return sprintf("accounts/%s", $accountId);
}
public static function listSubAccounts(array $config): 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.
$accountsServiceClient = new AccountsServiceClient($options);
// Creates parent/provider to identify the advanced account from which
//to list all accounts.
$parent = self::getParent($config['accountId']);
// Calls the API and catches and prints any network failures/errors.
try {
// The parent has the format: accounts/{account}
$request = new ListSubAccountsRequest(['provider' => $parent]);
print "Sending list subaccounts request:\n";
$response = $accountsServiceClient->listSubAccounts($request);
$count = 0;
// Iterates over all rows in all pages and prints the datasource in each row.
// Automatically uses the `nextPageToken` if returned to fetch all pages of data.
foreach ($response->iterateAllElements() as $account) {
print_r($account);
$count++;
}
print "The following count of accounts were returned: ";
print $count . PHP_EOL;
} catch (ApiException $e) {
print "An error has occured: \n";
print $e->getMessage();
}
}
public function callSample(): void
{
$config = Config::generateConfig();
self::listSubAccounts($config);
}
}
$sample = new ListSubAccounts();
$sample->callSample();
Python
from examples.authentication import configuration
from examples.authentication import generate_user_credentials
from google.shopping.merchant_accounts_v1 import AccountsServiceClient
from google.shopping.merchant_accounts_v1 import ListSubAccountsRequest
_ACCOUNT = configuration.Configuration().read_merchant_info()
def get_parent(account_id):
return f"accounts/{account_id}"
def list_sub_accounts():
"""Lists all the subaccounts of an advanced account."""
# Get OAuth credentials.
credentials = generate_user_credentials.main()
# Create a client.
client = AccountsServiceClient(credentials=credentials)
# Get the parent advanced account ID.
parent = get_parent(_ACCOUNT)
# Create the request.
request = ListSubAccountsRequest(provider=parent)
# Make the request and print the response.
try:
print("Sending list subaccounts request:")
response = client.list_sub_accounts(request=request)
count = 0
for account in response:
print(account)
count += 1
print(f"The following count of accounts were returned: {count}")
except RuntimeError as e:
print("An error has occured: ")
print(e)
if __name__ == "__main__":
list_sub_accounts()
cURL
curl -X GET \
"https://merchantapi.googleapis.com/accounts/v1/accounts/{ADVANCED_ACCOUNT_ID}:listSubaccounts" \
-H "Authorization: Bearer {YOUR_ACCESS_TOKEN}" \
حذف کردن حساب مشتری
اگر دیگر نیازی به مدیریت حساب مشتری ندارید، میتوانید آن را بااستفاده از روش
accounts.delete
حذف کنید.
اجرای این روش نیازمند دسترسی سرپرست به حسابی است که حذف میشود.
در اینجا یک درخواست نمونه آورده شده است:
DELETE https://merchantapi.googleapis.com/accounts/v1/accounts/{SUB_ACCOUNT_ID}
درصورت موفقیتآمیز بودن، بدنه پاسخ یک شیء JSON خالی است که نشان میدهد حساب حذف شده است.
نمونههای زیر نحوه حذف حساب مشتری را نشان میدهد.
جاوا
import com.google.api.gax.core.FixedCredentialsProvider;
import com.google.auth.oauth2.GoogleCredentials;
import com.google.shopping.merchant.accounts.v1.AccountName;
import com.google.shopping.merchant.accounts.v1.AccountsServiceClient;
import com.google.shopping.merchant.accounts.v1.AccountsServiceSettings;
import com.google.shopping.merchant.accounts.v1.DeleteAccountRequest;
import shopping.merchant.samples.utils.Authenticator;
import shopping.merchant.samples.utils.Config;
/** This class demonstrates how to delete a given Merchant Center account. */
public class DeleteAccountSample {
// This method can delete a standalone, advanced account or sub-account. If you delete an advanced
// account,
// all sub-accounts will also be deleted.
// Admin user access is required to execute this method.
public static void deleteAccount(Config config, String accountId) throws Exception {
// Obtains OAuth token based on the user's configuration.
GoogleCredentials credential = new Authenticator().authenticate();
// Creates service settings using the credentials retrieved above.
AccountsServiceSettings accountsServiceSettings =
AccountsServiceSettings.newBuilder()
.setCredentialsProvider(FixedCredentialsProvider.create(credential))
.build();
// Creates account name to identify the account.
String name =
AccountName.newBuilder()
.setAccount(accountId)
.build()
.toString();
// Calls the API.
try (AccountsServiceClient accountsServiceClient =
AccountsServiceClient.create(accountsServiceSettings)) {
DeleteAccountRequest request =
DeleteAccountRequest.newBuilder()
.setName(name)
// Optional. If set to true, the account will be deleted even if it has offers or
// provides services to other accounts. Defaults to 'false'.
.setForce(true)
.build();
System.out.println("Sending Delete Account request");
accountsServiceClient.deleteAccount(request); // No response returned on success.
System.out.println("Delete successful.");
}
}
public static void deleteAccount(Config config) throws Exception {
deleteAccount(config, config.getAccountId().toString());
}
public static void main(String[] args) throws Exception {
Config config = Config.load();
deleteAccount(config);
}
}
PHP
use Google\ApiCore\ApiException;
use Google\Shopping\Merchant\Accounts\V1\Client\AccountsServiceClient;
use Google\Shopping\Merchant\Accounts\V1\DeleteAccountRequest;
/**
* This class demonstrates how to delete a given Merchant Center account.
*/
class DeleteAccount
{
private static function getParent(string $accountId): string
{
return sprintf("accounts/%s", $accountId);
}
// This method can delete a standalone, advanced account or sub-account.
// If you delete an advanced account, all sub-accounts will also be deleted.
// Admin user access is required to execute this method.
public static function deleteAccount(array $config): 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.
$accountsServiceClient = new AccountsServiceClient($options);
// Gets the account ID from the config file.
$accountId = $config['accountId'];
// Creates account name to identify the account.
$name = self::getParent($accountId);
// Calls the API and catches and prints any network failures/errors.
try {
$request = new DeleteAccountRequest([
'name' => $name,
// Optional. If set to true, the account will be deleted even if it has offers or
// provides services to other accounts. Defaults to 'false'.
'force' => true,
]);
print "Sending Delete Account request\n";
$accountsServiceClient->deleteAccount($request); // No response returned on success.
print "Delete successful.\n";
} catch (ApiException $e) {
print $e->getMessage();
}
}
public function callSample(): void
{
$config = Config::generateConfig();
self::deleteAccount($config);
}
}
$sample = new DeleteAccount();
$sample->callSample();
Python
from examples.authentication import configuration
from examples.authentication import generate_user_credentials
from google.shopping.merchant_accounts_v1 import AccountsServiceClient
from google.shopping.merchant_accounts_v1 import DeleteAccountRequest
_ACCOUNT = configuration.Configuration().read_merchant_info()
def get_parent(account_id):
return f"accounts/{account_id}"
def delete_account():
"""Deletes a given Merchant Center account."""
# Get OAuth credentials.
credentials = generate_user_credentials.main()
# Create a client.
client = AccountsServiceClient(credentials=credentials)
# Create the account name.
name = get_parent(_ACCOUNT)
# Create the request.
request = DeleteAccountRequest(name=name, force=True)
# Make the request and print the response.
try:
print("Sending Delete Account request")
client.delete_account(request=request)
print("Delete successful.")
except RuntimeError as e:
print(e)
if __name__ == "__main__":
delete_account()
cURL
curl -X DELETE \
"https://merchantapi.googleapis.com/accounts/v1/accounts/{SUB_ACCOUNT_ID}?force=true" \
-H "Authorization: Bearer {YOUR_ACCESS_TOKEN}" \
پذیرفتن «شرایط خدمات»
حسابهای کارخواه شرایط خدمات Merchant Center (TOS) را که حساب پیشرفته مادر امضا کرده است به ارث میبرند.
بهروزرسانی اطلاعات کسبوکار
میتوانید از «میانای برنامهسازی کاربردی حسابهای Merchant» برای ویرایش اطلاعات کسبوکار حسابهای مشتریتان استفاده کنید.
- برای مشاهده اطلاعات کسبوکار حساب، با
accounts.getBusinessInfoتماس بگیرید. - برای ویرایش کردن اطلاعات کسبوکار حساب، با
accounts.updateBusinessInfoتماس بگیرید.