Nhóm địa điểm kinh doanh trên Google giống như một thư mục dùng chung cho các vị trí của bạn. Nhóm địa điểm kinh doanh là một cách an toàn để chia sẻ quyền quản lý các vị trí của bạn với nhiều người dùng. Để biết thêm thông tin, hãy xem bài viết Giới thiệu về nhóm địa điểm kinh doanh.
Trước khi tải kho hàng tại cửa hàng địa phương lên, hãy chỉ định nhóm địa điểm kinh doanh mà tài khoản Merchant Center của bạn sẽ chịu trách nhiệm. Bạn có thể lấy danh sách các nhóm doanh nghiệp đủ điều kiện từ Trang doanh nghiệp bằng Merchant API, nhưng trước tiên, để có quyền truy cập, bạn cần liên kết tài khoản của mình với một Trang doanh nghiệp.
Yêu cầu cấp quyền truy cập vào một Trang doanh nghiệp
Để có quyền truy cập vào một trang doanh nghiệp, hãy sử dụng phương thức gbpAccounts.LinkGbpAccount
:
POST https://merchantapi.googleapis.com/accounts/v1/accounts/<var>ACCOUNT_ID</var>/gbpAccounts:linkGbpAccount
{
"gbpEmail": "admin@example.com",
}
Thay thế nội dung sau:
ACCOUNT_ID
: giá trị nhận dạng duy nhất của tài khoản Merchant CenterGBP_EMAIL
: email của quản trị viên cho Trang doanh nghiệp
Khi gọi phương thức này, dịch vụ sẽ gửi email đến quản trị viên được chỉ định, yêu cầu chấp nhận hoặc từ chối yêu cầu truy cập. Nếu quản trị viên không phản hồi trong vòng 7 ngày, yêu cầu sẽ tự động hết hạn.
Liệt kê các nhóm địa điểm kinh doanh hiện có
Sau khi quản trị viên phê duyệt yêu cầu, bạn có thể kiểm tra các nhóm doanh nghiệp có sẵn bằng phương thức gbpAccounts.List
.
Sau đây là một yêu cầu mẫu và phản hồi thành công:
GET https://merchantapi.googleapis.com/accounts/v1/accounts/<var>ACCOUNT_ID</var>/gbpAccounts
Response:
200 OK
{
"gbpAccounts": [
{
"name": "accounts/<var>ACCOUNT</var>/gbpAccounts/12345",
"gbpAccountId": 12345,
"type": USER,
"gbpAccountName": "admin@example.com",
"listingCount": 15
}, {
"name": "accounts/<var>ACCOUNT</var>/gbpAccounts/67890",
"gbpAccountId": 67890,
"type": BUSINESS_ACCOUNT,
"gbpAccountName": "Google My Business Account",
"listingCount": 23
}
],
"nextPageToken": 50
}
Bạn có thể sử dụng mã mẫu này để truy xuất tất cả các nhóm doanh nghiệp đủ điều kiện:
package shopping.merchant.samples.accounts.v1;
// [START merchantapi_list_gbp_accounts]
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.GbpAccount;
import com.google.shopping.merchant.accounts.v1.GbpAccountsServiceClient;
import com.google.shopping.merchant.accounts.v1.GbpAccountsServiceClient.ListGbpAccountsPagedResponse;
import com.google.shopping.merchant.accounts.v1.GbpAccountsServiceSettings;
import com.google.shopping.merchant.accounts.v1.ListGbpAccountsRequest;
import shopping.merchant.samples.utils.Authenticator;
import shopping.merchant.samples.utils.Config;
/**
* This class demonstrates how to get the list of GBP accounts for a given Merchant Center account
*/
public class ListGbpAccountsSample {
public static void listGbpAccounts(Config config) throws Exception {
// Obtains OAuth token based on the user's configuration.
GoogleCredentials credential = new Authenticator().authenticate();
// Creates service settings using the retrieved credentials.
GbpAccountsServiceSettings gbpAccountsServiceSettings =
GbpAccountsServiceSettings.newBuilder()
.setCredentialsProvider(FixedCredentialsProvider.create(credential))
.build();
String accountId = config.getAccountId().toString();
// Creates parent to identify the omnichannelSetting from which to list all Lfp Providers.
String parent = AccountName.newBuilder().setAccount(accountId).build().toString();
// Calls the API and catches and prints any network failures/errors.
try (GbpAccountsServiceClient gbpAccountsServiceClient =
GbpAccountsServiceClient.create(gbpAccountsServiceSettings)) {
ListGbpAccountsRequest request =
ListGbpAccountsRequest.newBuilder().setParent(parent).build();
System.out.println("Sending list GBP accounts request:");
ListGbpAccountsPagedResponse response = gbpAccountsServiceClient.listGbpAccounts(request);
int count = 0;
// Iterates over all the entries in the response.
for (GbpAccount gbpAccount : response.iterateAll()) {
System.out.println(gbpAccount);
count++;
}
System.out.println(String.format("The following count of elements were returned: %d", count));
} catch (Exception e) {
System.out.println("An error has occurred: ");
System.out.println(e);
}
}
public static void main(String[] args) throws Exception {
Config config = Config.load();
listGbpAccounts(config);
}
}
// [END merchantapi_list_gbp_accounts]
Chỉ định nhóm địa điểm kinh doanh cho tài khoản Merchant Center
danh sách các nhóm địa điểm kinh doanh hiện có, bạn có thể liên kết nhóm địa điểm kinh doanh đó với tài khoản Merchant Center. Ví dụ: nếu muốn chọn nhóm doanh nghiệp có mã tài khoản GBP 12345
(được trả về từ bước trước), bạn có thể sử dụng AccountServices.proposeAccountService
:
POST
https://merchantapi.googleapis.com/accounts/v1/accounts/<var>ACCOUNT_ID</var>/services:propose
{
provider: "providers/GOOGLE_BUSINESS_PROFILE",
account_service: {
external_account_id: "12345",
local_listing_management {}
}
}
Xin lưu ý rằng trường provider
phải là providers/GOOGLE_BUSINESS_PROFILE
. Bạn phải đặt trường LocalListingManagement
trống trong yêu cầu.
Gửi dữ liệu sản phẩm và kho hàng
Giờ đây, khi đã liên kết tài khoản Merchant Center với một nhóm địa điểm kinh doanh, bạn có thể tải dữ liệu sản phẩm và kho hàng tại địa phương lên. Để biết thêm thông tin, hãy xem