Google 商家群组就像是营业地点的一个共享文件夹。商家群组提供了一种安全的方式,以便您与多个用户共享您的地点信息管理权限。如需了解详情,请参阅商家群组简介。
在上传本地商品目录之前,请指定您的 Merchant Center 账号将负责的商家群组。您可以使用 Merchant API 从商家资料中获取符合条件的商家群组列表,但若要获得访问权限,您需要先将您的账号与商家资料相关联。
请求访问商家资料
如需获取对商家资料的访问权限,请使用 gbpAccounts.LinkGbpAccount
方法:
POST https://merchantapi.googleapis.com/accounts/v1/accounts/<var>ACCOUNT_ID</var>/gbpAccounts:linkGbpAccount
{
"gbpEmail": "admin@example.com",
}
替换以下内容:
ACCOUNT_ID
:您的 Merchant Center 账号的唯一标识符GBP_EMAIL
:商家资料管理员的电子邮件地址
调用此方法后,服务会向指定的管理员发送一封电子邮件,要求其接受或拒绝访问请求。如果管理员未在 7 天内回复,该请求将自动过期。
列出可用的商家群组
管理员批准请求后,您可以使用 gbpAccounts.List
方法查看可用的商家群组。
以下是请求和成功响应示例:
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
}
您可以使用以下代码示例检索所有符合条件的商家群组:
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]
为 Merchant Center 账号指定商家群组
列表中,然后将该商家群组与您的 Merchant Center 账号相关联。例如,如果您想选择 GBP 账号 ID 为 12345
(从上一步返回)的商家群组,可以使用 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 {}
}
}
请注意,provider
字段必须是 providers/GOOGLE_BUSINESS_PROFILE
。您必须在请求中设置一个空的 LocalListingManagement
字段。
提交商品和商品目录数据
现在,您已将 Merchant Center 账号与商家群组相关联,接下来可以上传商品和本地商品目录数据了。如需了解详情,请参阅