Google 營業地點群組就好比營業地點的共用資料夾,你可以透過營業地點群組,安全地與多位使用者共同管理營業地點資訊。詳情請參閱「關於營業地點群組」。
上傳店面商品目錄前,請指定 Merchant Center 帳戶負責的營業地點群組。您可以使用 Merchant API 從商家檔案取得符合資格的營業地點群組清單,但您必須先將帳戶連結至商家檔案,才能取得存取權。
要求存取商家檔案
如要取得商家檔案的存取權,請使用 gbpAccounts.LinkGbpAccount
方法:
POST https://merchantapi.googleapis.com/accounts/v1beta/accounts/<var>ACCOUNT_ID</var>/gbpAccounts:linkGbpAccount
{
"gbpEmail": "admin@example.com",
}
更改下列內容:
ACCOUNT_ID
:Merchant Center 帳戶的專屬 IDGBP_EMAIL
:商家檔案管理員的電子郵件地址
呼叫此方法時,服務會傳送電子郵件給指定的管理員,要求他們接受或拒絕存取要求。如果管理員未在 7 天內回覆,要求就會自動失效。
列出可用的營業地點群組
管理員核准要求後,您可以使用 gbpAccounts.List
方法查看可用的商家群組。
以下是要求和成功回應的範例:
GET https://merchantapi.googleapis.com/accounts/v1beta/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
}
您可以使用這個程式碼範例擷取所有符合資格的商家群組:
package shopping.merchant.samples.accounts.v1beta;
// [START merchantapi_list_gbp_accounts]
import com.google.api.gax.core.FixedCredentialsProvider;
import com.google.auth.oauth2.GoogleCredentials;
import com.google.shopping.merchant.accounts.v1beta.AccountName;
import com.google.shopping.merchant.accounts.v1beta.GbpAccount;
import com.google.shopping.merchant.accounts.v1beta.GbpAccountsServiceClient;
import com.google.shopping.merchant.accounts.v1beta.GbpAccountsServiceClient.ListGbpAccountsPagedResponse;
import com.google.shopping.merchant.accounts.v1beta.GbpAccountsServiceSettings;
import com.google.shopping.merchant.accounts.v1beta.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]
指定 Merchant Center 帳戶的營業地點群組
可用的營業地點群組清單,即可將營業地點群組與 Merchant Center 帳戶建立關聯。舉例來說,如果您想選擇使用 GBP 帳戶 ID 12345
(從上一個步驟傳回) 的商家群組,可以使用 AccountServices.proposeAccountService
:
POST
https://merchantapi.googleapis.com/accounts/v1beta/accounts/<var>ACCOUNT_ID</var>/services:propose
{
provider: "providers/GOOGLE_BUSINESS_PROFILE",
account_service: {
external_account_id: "12345",
local_listing_management {}
}
}
請注意,provider
欄位必須是 providers/GOOGLE_BUSINESS_PROFILE
。您必須在要求中設定空白的 LocalListingManagement
欄位。
提交產品和商品目錄資料
將 Merchant Center 帳戶與營業地點群組建立關聯後,即可上傳產品和店面商品目錄資料。詳情請參閱