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 アカウントをビジネス拠点グループに関連付けたら、商品データとローカル在庫データをアップロードできます。詳しくは、