Bạn có thể sử dụng Merchant API để tạo tài khoản Merchant Center. Tài khoản này có thể được liên kết với một tài khoản nâng cao bằng cách sử dụng accountAggregation, accountManagement hoặc comparisonShopping. Phương thức accounts.createAndConfigure cho phép bạn tạo một tài khoản và tuỳ ý định cấu hình tài khoản đó với người dùng, đồng thời liên kết tài khoản đó với các tài khoản khác thông qua các dịch vụ.
Hướng dẫn này giải thích cách sử dụng Merchant API để tạo tài khoản bằng các dịch vụ như accountManagement, comparisonShopping hoặc accountAggregation. Khi sử dụng accounts.createAndConfigure, bạn phải liên kết tài khoản mới với một nhà cung cấp bằng cách chỉ định ít nhất một trong các giá trị accountAggregation, accountManagement hoặc comparisonShopping trong trường service.
Bạn có thể chỉ định accountAggregation và comparisonShopping trong cùng một yêu cầu, nhưng không thể kết hợp accountManagement với accountAggregation hoặc comparisonShopping.
Nếu chỉ định accountManagement, bạn cũng phải thêm ít nhất một người dùng vào tài khoản mới bằng trường user hoặc users.
Điều kiện tiên quyết
Trước khi có thể tạo tài khoản bằng Merchant API, hãy đảm bảo bạn đáp ứng các yêu cầu sau, tuỳ thuộc vào dịch vụ bạn sử dụng:
- Quyền quản trị: Bạn phải có quyền quản trị đối với tài khoản nhà cung cấp khi liên kết một tài khoản mới bằng
accountManagement,comparisonShoppinghoặcaccountAggregation. - Tài khoản nâng cao: Nếu bạn sử dụng
accountAggregation, thì tài khoản nhà cung cấp của bạn phải là một tài khoản nâng cao được định cấu hình để tổng hợp tài khoản. Nếu bạn là nhà cung cấp dịch vụ và cần thiết lập tài khoản nâng cao, hãy liên hệ với nhóm hỗ trợ để được trợ giúp về việc thiết lập.
Tạo tài khoản (sử dụng tính năng quản lý tài khoản hoặc dịch vụ so sánh giá)
Để tạo tài khoản mới, hãy gọi accounts.createAndConfigure.
Đây là phương pháp được đề xuất cho những đối tác giúp người bán quản lý tài khoản của họ, vì phương pháp này cho phép người bán giữ toàn quyền kiểm soát và sở hữu tài khoản của họ, đồng thời cấp các quyền cụ thể cho đối tác.
Trong nội dung yêu cầu:
- Cung cấp thông tin chi tiết về tài khoản mà bạn muốn tạo trong trường
account. - Nếu bạn đang sử dụng
accountManagement, hãy chỉ định ít nhất một người dùng trong trườnguser. Người dùng này sẽ có quyền truy cập vào tài khoản. - Trong trường
service, hãy chỉ định mọi dịch vụ mà bạn muốn cung cấp cho tài khoản này, ví dụ:accountManagementvà đặtproviderthành tên tài nguyên của tài khoản (ví dụ:providers/{YOUR_ACCOUNT_ID}). Hãy xem phần Quản lý mối quan hệ tài khoản để biết danh sách các dịch vụ có sẵn, chẳng hạn nhưproductsManagementhoặccampaignsManagement.
Dưới đây là ví dụ về yêu cầu tạo một tài khoản có tên "merchantStore" và liên kết tài khoản đó với tài khoản {YOUR_ACCOUNT_ID} để quản lý tài khoản và sản phẩm:
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}"
}
]
}
Một lệnh gọi thành công sẽ tạo tài khoản mới và liên kết tài khoản đó với tài khoản của bạn cho các dịch vụ được chỉ định. Nếu bạn chỉ định các dịch vụ accountManagement, accountAggregation hoặc comparisonShopping trong quá trình tạo, thì các dịch vụ đó sẽ tự động được phê duyệt và trạng thái liên kết là ESTABLISHED. Các mối liên kết với dịch vụ khác có thể ở trạng thái PENDING cho đến khi tài khoản được tạo chấp nhận. Phần nội dung phản hồi chứa tài nguyên Account mới tạo.
Sau khi tạo tài khoản như vậy, bạn cần tham gia bằng cách thực hiện các bước như chấp nhận Điều khoản dịch vụ, thiết lập thông tin doanh nghiệp và xác minh trang web.
Ngăn chặn quy trình xác minh email trong quá trình tạo tài khoản
Khi tạo tài khoản bằng accounts.createAndConfigure, bạn có thể tuỳ ý chặn email xác minh cho người dùng mới được thêm bằng cách sử dụng trường user bằng cách đặt verificationMailSettings.verificationMailMode thành SUPPRESS_VERIFICATION_MAIL trong yêu cầu cho người dùng đó. Điều này sẽ hữu ích nếu bạn dự định xác minh người dùng thay mặt cho người bán ngay sau khi tạo bằng phương thức users.verifySelf. Theo mặc định, verificationMailMode là SEND_VERIFICATION_MAIL và email xác minh sẽ được gửi cho những người dùng mới được thêm trong quá trình tạo tài khoản.
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}"
}
]
}
Nếu đặt verificationMailMode thành SUPPRESS_VERIFICATION_MAIL, bạn cần gọi users.verifySelf cho mỗi người dùng được thêm trong quá trình tạo để hoàn tất quy trình xác minh. Lệnh gọi này phải được xác thực là người dùng đang được xác minh (người dùng được chỉ định trong userId), ví dụ: bằng cách sử dụng mã thông báo OAuth của người dùng.
Chỉ định một biệt hiệu trong quá trình tạo tài khoản
Bạn có thể chỉ định một biệt hiệu cho tài khoản trong bối cảnh của một nhà cung cấp trong CreateAndConfigureAccountRequest bằng cách sử dụng trường setAlias. Bạn có thể dùng biệt hiệu này để xác định tài khoản trong hệ thống của mình. Nếu là nhà cung cấp dịch vụ, bạn có thể dùng biệt hiệu để truy xuất tài khoản bằng GET /accounts/v1/accounts/{provider}~{alias}. Tên thay thế phải là duy nhất đối với một nhà cung cấp nhất định và bạn phải chỉ định một dịch vụ có cùng nhà cung cấp trong trường service của yêu cầu. Để biết thêm thông tin về các yêu cầu đối với tên thay thế, hãy xem bài viết Quản lý mối quan hệ giữa các tài khoản.
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"
}
]
}
Quy trình giới thiệu được đề xuất
Nếu là đối tác tạo tài khoản thay mặt cho người bán, bạn nên thực hiện theo quy trình sau:
- Tạo tài khoản: Gọi
accounts.createAndConfigurebằng thông tin đăng nhập của đối tác để tạo một tài khoản mới.- Đặt
serviceđể thêmaccountManagementliên kết đến mã nhận dạng nhà cung cấp của bạn. - Thêm người bán làm người dùng bằng cách sử dụng trường
uservà đặtverificationMailSettings.verificationMailModethànhSUPPRESS_VERIFICATION_MAIL.
- Đặt
- Xác minh người dùng: Bằng thông tin đăng nhập của người bán (ví dụ: sử dụng mã thông báo OAuth), hãy gọi
users.verifySelfđể thay đổi trạng thái người dùng từPENDINGthànhVERIFIED. - Đặt quốc gia của doanh nghiệp: Bằng thông tin đăng nhập của người bán, hãy đặt quốc gia của doanh nghiệp bằng cách cập nhật
address.regionCodebằngaccounts.updateBusinessInfo. Bạn phải làm việc này trước khi chấp nhận Điều khoản dịch vụ. - Chấp nhận Điều khoản dịch vụ: Bằng thông tin đăng nhập của người bán, hãy chấp nhận Điều khoản dịch vụ.
Quy trình này giúp người bán dễ dàng tham gia nền tảng của bạn mà không cần nhận email mời từ Google.
Tạo tài khoản khách hàng (sử dụng tính năng tổng hợp tài khoản)
Tài khoản khách hàng là các tài khoản Merchant Center riêng biệt được liên kết với tài khoản nâng cao của bạn bằng dịch vụ accountAggregation, cho phép quản lý tập trung trong khi vẫn duy trì các chế độ cài đặt, trang web và nguồn cấp dữ liệu riêng biệt.
Bạn có thể sử dụng API phụ Tài khoản người bán để tạo tài khoản khách hàng mới.
Để tạo tài khoản khách hàng, trước tiên, bạn phải có chế độ thiết lập tài khoản nâng cao. Bạn phải là quản trị viên tài khoản để chuyển đổi tài khoản Merchant Center của mình thành tài khoản nâng cao và tài khoản của bạn không được có vấn đề nào đang chờ xử lý.
Để tạo tài khoản khách hàng mới, hãy gọi accounts.createAndConfigure.
Trong nội dung yêu cầu:
- Cung cấp thông tin chi tiết về tài khoản mà bạn muốn tạo trong trường
account. - Bạn có thể chỉ định người dùng được uỷ quyền mới trong trường
user(không bắt buộc). Quyền truy cập của người dùng vào tài khoản cũng được kế thừa từ tài khoản nâng cao mẹ. - Trong trường
service, hãy chỉ địnhaccountAggregationvà đặtproviderthành tên tài nguyên của tài khoản nâng cao (ví dụ:providers/{ADVANCED_ACCOUNT_ID}). Thao tác này sẽ thiết lập tài khoản nâng cao làm đơn vị tổng hợp cho tài khoản mới.
Sau đây là ví dụ về yêu cầu tạo một tài khoản khách hàng có tên là "merchantStore" được liên kết với tài khoản nâng cao {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}"
}
]
}
Một lệnh gọi thành công sẽ tạo tài khoản khách hàng mới và liên kết tài khoản đó với tài khoản nâng cao mà bạn chỉ định. Phần nội dung phản hồi sẽ chứa tài nguyên Account mới tạo.
Các mẫu sau đây minh hoạ cách bạn có thể sử dụng accounts.createAndConfigure để tạo một tài khoản khách hàng mới.
Java
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 void 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());
} catch (Exception e) {
System.out.println(e);
}
}
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}"
}
]
}'
Truy xuất tài khoản khách hàng
Để liệt kê tất cả tài khoản khách hàng của một tài khoản nâng cao nhất định, hãy sử dụng phương thức accounts.listSubaccounts. Cung cấp mã nhận dạng tài khoản nâng cao của bạn trong trường provider của URL yêu cầu.
Sau đây là một yêu cầu mẫu:
GET https://merchantapi.googleapis.com/accounts/v1/accounts/{ADVANCED_ACCOUNT_ID}:listSubaccounts
Sau đây là một phản hồi mẫu từ một lệnh gọi thành công:
{
"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"
}
]
}
Các mẫu sau đây minh hoạ cách liệt kê tất cả tài khoản khách hàng của tài khoản nâng cao.
Java
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 void 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);
} catch (Exception e) {
System.out.println("An error has occured: ");
System.out.println(e);
}
}
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>"
Xoá tài khoản khách hàng
Nếu không cần quản lý tài khoản khách hàng nữa, bạn có thể xoá tài khoản đó bằng phương thức accounts.delete.
Để thực hiện phương thức này, bạn phải có quyền truy cập của quản trị viên vào tài khoản sẽ bị xoá.
Sau đây là một yêu cầu mẫu:
DELETE https://merchantapi.googleapis.com/accounts/v1/accounts/{SUB_ACCOUNT_ID}
Nếu thành công, phần nội dung phản hồi sẽ là một đối tượng JSON trống, cho biết tài khoản đã bị xoá.
Các mẫu sau đây minh hoạ cách xoá một tài khoản khách hàng.
Java
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) 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();
// Gets the account ID from the config file.
String accountId = config.getAccountId().toString();
// Creates account name to identify the account.
String name =
AccountName.newBuilder()
.setAccount(accountId)
.build()
.toString();
// Calls the API and catches and prints any network failures/errors.
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.");
} catch (Exception e) {
System.out.println(e);
}
}
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>"
Chấp nhận Điều khoản dịch vụ
Tài khoản khách hàng kế thừa Điều khoản dịch vụ (TOS) của Merchant Center mà tài khoản nâng cao chính đã ký.
Cập nhật thông tin doanh nghiệp
Bạn có thể sử dụng Merchant Accounts API để chỉnh sửa thông tin doanh nghiệp cho tài khoản khách hàng.
- Để xem thông tin doanh nghiệp của một tài khoản, hãy gọi
accounts.getBusinessInfo.- Để chỉnh sửa thông tin doanh nghiệp của một tài khoản, hãy gọi
accounts.updateBusinessInfo.
- Để chỉnh sửa thông tin doanh nghiệp của một tài khoản, hãy gọi