Połącz profil firmy w Google

Grupa firmowa Google to folder wspólny z lokalizacjami. Dzięki grupie firmowej wielu użytkowników może bezpiecznie zarządzać lokalizacjami. Więcej informacji znajdziesz w artykule Informacje o grupach firmowych.

Zanim prześlesz asortyment lokalny, określ grupę firmową, za którą będzie odpowiadać Twoje konto Merchant Center. Listę kwalifikujących się grup firmowych możesz uzyskać z Profilu Firmy za pomocą interfejsu Merchant API, ale aby uzyskać dostęp, musisz najpierw połączyć swoje konto z Profilem Firmy.

Prośba o dostęp do profilu firmy

Aby uzyskać dostęp do profilu firmy, użyj metody gbpAccounts.LinkGbpAccount:

POST https://merchantapi.googleapis.com/accounts/v1/accounts/<var>ACCOUNT_ID</var>/gbpAccounts:linkGbpAccount

{
  "gbpEmail": "admin@example.com",
}

Zastąp następujące elementy:

  • ACCOUNT_ID: unikalny identyfikator Twojego konta Merchant Center
  • GBP_EMAIL: adres e-mail administratora Profilu Firmy

Po wywołaniu tej metody usługa wysyła e-maila do określonego administratora z prośbą o zaakceptowanie lub odrzucenie prośby o dostęp. Jeśli administrator nie odpowie w ciągu 7 dni, prośba wygaśnie automatycznie.

Lista dostępnych grup firmowych

Gdy administrator zatwierdzi prośbę, możesz sprawdzić dostępne grupy firmowe, korzystając z metody gbpAccounts.List.

Oto przykładowa prośba i odpowiedź:

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
}

Możesz użyć tego przykładowego kodu, aby pobrać wszystkie odpowiednie grupy firm:

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]

Wskaż grupę firmową konta Merchant Center

listę dostępnych grup firmowych, z którymi możesz powiązać grupę firmową z kontem Merchant Center. Jeśli na przykład chcesz wybrać grupę firm o identyfikatorze konta GBP 12345 (zwróconym z poprzedniego kroku), możesz użyć 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 {}
  }
}

Pamiętaj, że pole provider musi być providers/GOOGLE_BUSINESS_PROFILE. W żądaniu musisz ustawić puste pole LocalListingManagement.

Przesyłanie danych produktów i danych o asortymencie

Po powiązaniu konta Merchant Center z grupą firmową możesz przesłać dane o produktach i lokalnym asortymencie. Więcej informacji znajdziesz w artykule