Zarządzanie ustawieniami Omnichannel

Interfejs API ustawień wielokanałowych to punkt wejścia do konfigurowania programów reklam lokalnego asortymentu produktów i bezpłatnych lokalnych informacji.

Za jego pomocą możesz programowo:

  • zarządzać ustawieniami wielokanałowymi (tworzyć i aktualizować);
  • pobierać ustawienia wielokanałowe (pobierać i wyświetlać listę);
  • prosić o weryfikację asortymentu w przypadku kwalifikujących się sprzedawców.

Więcej informacji znajdziesz w artykule Omówienie reklam lokalnego asortymentu produktów i bezpłatnych lokalnych informacji.

Wymagania wstępne

Musisz mieć:

  • konto Merchant Center;

  • Profil Firmy. Jeśli go nie masz, możesz go utworzyć. Więcej informacji znajdziesz w artykule Rejestracja w usłudze Profil Firmy.

  • Połączenie między Profilem Firmy a kontem Merchant Center. Aby utworzyć połączenie, możesz użyć interfejsu Merchant Center lub interfejsu Merchant API (więcej informacji znajdziesz w artykule Łączenie Profilu Firmy w Google).

Tworzenie ustawienia wielokanałowego

Ustawienie wielokanałowe możesz utworzyć za pomocą metody omnichannelSettings.create. Metoda create przyjmuje jako dane wejściowe zasób omnichannelSetting i w przypadku powodzenia zwraca utworzone ustawienie wielokanałowe.

Podczas tworzenia musisz wypełnić pola regionCode i LsfType:

  • Ustawienie wielokanałowe jest tworzone dla każdego kraju. RegionCode określa kraj docelowy. Po utworzeniu nie można go zmienić. RegionCode powinien być zgodny z regułą nazewnictwa określoną przez projekt Common Locale Data Repository (CLDR).
  • LsfType zależy od strony produktu. Więcej informacji znajdziesz w artykule LsfType.

Więcej informacji znajdziesz w artykule Zmiana jakości strony produktu dla reklam lokalnego asortymentu produktów.

Podczas tworzenia nie musisz wypełniać wszystkich pól. Możesz je skonfigurować później. Aby zaktualizować istniejący element omnichannelSetting, zobacz Aktualizowanie ustawienia wielokanałowego.

Oto przykładowe żądanie, jeśli wybierzesz MHLSF_BASIC i zarejestrujesz inStock:

POST https://merchantapi.googleapis.com/accounts/v1/accounts/{ACCOUNT_ID}/omnichannelSettings

{
  "regionCode": "{REGION_CODE}",
  "lsfType: "MHLSF_BASIC",
  "inStock": {
      "uri": {URI}"
  }
}

Zastąp następujące elementy:

  • {ACCOUNT_ID}: unikalny identyfikator konta Merchant Center.
  • {REGION_CODE}: kod regionu zdefiniowany przez CLDR.
  • {URI}: prawidłowy identyfikator URI używany w przypadku danej opinii. Nieprawidłowy identyfikator URI może uniemożliwić zatwierdzenie.

Po pomyślnym wykonaniu żądania powinna pojawić się taka odpowiedź:

{
  "name": "accounts/{ACCOUNT_ID}/omnichannelSettings/{omnichannel_setting}",
  "regionCode": "{REGION_CODE}",
  "lsfType: "MHLSF_BASIC",
  "inStock": {
      "uri": "{URI}",
      "state": "RUNNING"
  }
}

Rejestrowanie różnych funkcji reklam lokalnego asortymentu produktów i bezpłatnych lokalnych informacji za pomocą pól omnichannelSetting powoduje ręczne sprawdzanie, które zwykle trwa od kilku godzin do kilku dni. Zalecamy dokładne sprawdzenie danych wejściowych, aby uniknąć niepotrzebnego czasu oczekiwania spowodowanego nieprawidłowymi danymi.

Aby wyświetlić nowo utworzone ustawienie wielokanałowe lub sprawdzić stan opinii, użyj metody accounts.omnichannelSettings.get lub accounts.omnichannelSettings.list, określając kraj.

Typ lokalnej witryny sklepowej

W zależności od strony produktu, której chcesz używać, wybierz LsfType:

Typ strony produktu LsfType Wartość typu enum
Strony produktów z danymi o dostępności w sklepie Lokalna witryna sklepowa sprzedawcy (podstawowa) MHLSF_BASIC
Strony produktów w konkretnym sklepie z informacjami o dostępności i cenie Lokalna witryna sklepowa sprzedawcy (pełna implementacja) MHLSF_FULL
Strony produktów bez informacji o dostępności w sklepie Lokalna witryna sklepowa hostowana przez Google GHLSF

Jeśli wybierzesz typy lokalnej witryny sklepowej sprzedawcy, musisz też wypełnić pole URI co najmniej w przypadku jednej z opcji: inStock lub pickup.

InStock

Za pomocą opcji InStock możesz podać więcej informacji o stronie produktu.

Jeśli wybierzesz typy lokalnej witryny sklepowej sprzedawcy i określisz pole URI w opcji InStock, pokażesz, że chcesz wyświetlać produkty z informacjami o dostępności w sklepie. Rozpoczniemy sprawdzanie na podstawie podanego identyfikatora URI.

Jeśli wybierzesz typ GHLSF, musisz podać puste pole InStock w żądaniu. W przeciwieństwie do typów lokalnej witryny sklepowej sprzedawcy, aby zakończyć proces rejestracji, musisz przejść proces weryfikacji asortymentu.

Ten przykładowy kod tworzy omnichannelSetting z GHLSF:

Java

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.CreateOmnichannelSettingRequest;
import com.google.shopping.merchant.accounts.v1.InStock;
import com.google.shopping.merchant.accounts.v1.OmnichannelSetting;
import com.google.shopping.merchant.accounts.v1.OmnichannelSetting.LsfType;
import com.google.shopping.merchant.accounts.v1.OmnichannelSettingsServiceClient;
import com.google.shopping.merchant.accounts.v1.OmnichannelSettingsServiceSettings;
import shopping.merchant.samples.utils.Authenticator;
import shopping.merchant.samples.utils.Config;

/**
 * This class demonstrates how to create an omnichannel setting for a given Merchant Center account
 * in a given country
 */
public class CreateOmnichannelSettingSample {

  public static void createOmnichannelSetting(Config config, String regionCode) throws Exception {

    // Obtains OAuth token based on the user's configuration.
    GoogleCredentials credential = new Authenticator().authenticate();

    // Creates service settings using the credentials retrieved above.
    OmnichannelSettingsServiceSettings omnichannelSettingsServiceSettings =
        OmnichannelSettingsServiceSettings.newBuilder()
            .setCredentialsProvider(FixedCredentialsProvider.create(credential))
            .build();

    // Calls the API and catches and prints any network failures/errors.
    try (OmnichannelSettingsServiceClient omnichannelSettingsServiceClient =
        OmnichannelSettingsServiceClient.create(omnichannelSettingsServiceSettings)) {
      String accountId = config.getAccountId().toString();
      String parent = AccountName.newBuilder().setAccount(accountId).build().toString();

      // Creates an omnichannel setting with GHLSF type in the given country.
      CreateOmnichannelSettingRequest request =
          CreateOmnichannelSettingRequest.newBuilder()
              .setParent(parent)
              .setOmnichannelSetting(
                  OmnichannelSetting.newBuilder()
                      .setRegionCode(regionCode)
                      .setLsfType(LsfType.GHLSF)
                      .setInStock(InStock.getDefaultInstance())
                      .build())
              .build();

      System.out.println("Sending create omnichannel setting request:");
      OmnichannelSetting response =
          omnichannelSettingsServiceClient.createOmnichannelSetting(request);

      System.out.println("Inserted Omnichannel Setting below:");
      System.out.println(response);
    } catch (Exception e) {
      System.out.println("An error has occured: ");
      System.out.println(e);
    }
  }

  public static void main(String[] args) throws Exception {
    Config config = Config.load();

    // The country which you're targeting at.
    String regionCode = "{REGION_CODE}";

    createOmnichannelSetting(config, regionCode);
  }
}

PHP

use Google\ApiCore\ApiException;
use Google\Shopping\Merchant\Accounts\V1\Client\OmnichannelSettingsServiceClient;
use Google\Shopping\Merchant\Accounts\V1\CreateOmnichannelSettingRequest;
use Google\Shopping\Merchant\Accounts\V1\InStock;
use Google\Shopping\Merchant\Accounts\V1\OmnichannelSetting;
use Google\Shopping\Merchant\Accounts\V1\OmnichannelSetting\LsfType;

/**
 * This class demonstrates how to create an omnichannel setting for a given
 * Merchant Center account in a given country.
 */
class CreateOmnichannelSetting
{
    /**
     * Helper to create the parent string.
     *
     * @param string $accountId The merchant account ID.
     * @return string The parent string in the format `accounts/{account}`.
     */
    private static function getParent(string $accountId): string
    {
        return sprintf('accounts/%s', $accountId);
    }

    /**
     * Creates an omnichannel setting for a given Merchant Center account.
     *
     * @param array $config The configuration file for authentication.
     * @param string $regionCode The country for the omnichannel setting.
     */
    public static function createOmnichannelSettingSample(
        array $config,
        string $regionCode
    ): void {
        // Obtains OAuth credentials from the configuration file.
        $credentials = Authentication::useServiceAccountOrTokenFile();

        // Creates a client.
        $omnichannelSettingsServiceClient = new OmnichannelSettingsServiceClient([
            'credentials' => $credentials
        ]);

        // Constructs the parent resource name.
        $parent = self::getParent($config['accountId']);

        // Creates the omnichannel setting with GHLSF type in the given country.
        $omnichannelSetting = new OmnichannelSetting([
            'region_code' => $regionCode,
            'lsf_type' => LsfType::GHLSF,
            'in_stock' => new InStock()
        ]);

        // Creates the request.
        $request = new CreateOmnichannelSettingRequest([
            'parent' => $parent,
            'omnichannel_setting' => $omnichannelSetting
        ]);

        // Calls the API and prints the response.
        try {
            printf("Sending create omnichannel setting request:%s", PHP_EOL);
            $response = $omnichannelSettingsServiceClient->createOmnichannelSetting($request);
            printf("Inserted Omnichannel Setting below:%s", PHP_EOL);
            print $response->serializeToJsonString(true) . PHP_EOL;
        } catch (ApiException $e) {
            printf("An error has occured: %s", $e->getMessage());
        }
    }

    /**
     * Executes the sample.
     */
    public function callSample(): void
    {
        $config = Config::generateConfig();
        // The country which you're targeting.
        $regionCode = '{REGION_CODE}';
        self::createOmnichannelSettingSample($config, $regionCode);
    }
}

// Runs the script.
$sample = new CreateOmnichannelSetting();
$sample->callSample();

Python

from examples.authentication import configuration
from examples.authentication import generate_user_credentials
from google.shopping.merchant_accounts_v1 import CreateOmnichannelSettingRequest
from google.shopping.merchant_accounts_v1 import InStock
from google.shopping.merchant_accounts_v1 import OmnichannelSetting
from google.shopping.merchant_accounts_v1 import OmnichannelSettingsServiceClient


def create_omnichannel_setting(account_id: str, region_code: str) -> None:
  """Creates an omnichannel setting for a given Merchant Center account.

  Args:
      account_id: The ID of the Merchant Center account.
      region_code: The country for which you're creating the setting.
  """
  # Gets OAuth Credentials.
  credentials = generate_user_credentials.main()

  # Creates a client.
  client = OmnichannelSettingsServiceClient(credentials=credentials)

  # The parent account under which to create the setting.
  parent = f"accounts/{account_id}"

  # Creates an omnichannel setting with GHLSF type in the given country.
  omnichannel_setting = OmnichannelSetting()
  omnichannel_setting.region_code = region_code
  omnichannel_setting.lsf_type = OmnichannelSetting.LsfType.GHLSF
  omnichannel_setting.in_stock = InStock()

  # Creates the request.
  request = CreateOmnichannelSettingRequest(
      parent=parent, omnichannel_setting=omnichannel_setting
  )

  # Makes the request and catches and prints any error messages.
  try:
    print("Sending create omnichannel setting request:")
    response = client.create_omnichannel_setting(request=request)
    print("Inserted Omnichannel Setting below:")
    print(response)
  except RuntimeError as e:
    print("An error has occured: ")
    print(e)


if __name__ == "__main__":
  # The ID of the account to get the omnichannel settings for.
  _ACCOUNT = configuration.Configuration().read_merchant_info()

  # The country which you're targeting.
  _REGION_CODE = "{REGION_CODE}"

  create_omnichannel_setting(_ACCOUNT, _REGION_CODE)

Odbiór

Oprócz informacji o dostępności w sklepie możesz też dodać do produktów dostępnych w sklepie funkcję odbioru, która jest dostępna tylko w przypadku typów lokalnej witryny sklepowej sprzedawcy.

Gdy produkt jest oznaczony jako dostępny do odbioru, oznacza to, że klient może go kupić online i odebrać w sklepie. Ustawiając pole Pickup, pokazujesz swoją intencję wyświetlania produktów z gwarantowaną dostępnością produktu do odbioru. Rozpoczniemy sprawdzanie na podstawie podanego identyfikatora URI.

Oto przykładowe żądanie, które tworzy ustawienie omnichannel z Pickup:

POST https://merchantapi.googleapis.com/accounts/v1/accounts/{ACCOUNT_ID}/omnichannelSettings

{
  "regionCode": "{REGION_CODE}",
  "lsfType: "MHLSF_BASIC",
  "pickup": {
     "uri: "{URI}"
  }
}

Dostępność na zamówienie

Dzięki funkcji „ Dostępność na zamówienie ” możesz pokazać produkty, które są wystawione w Twoich sklepach stacjonarnych, ale nie są dostępne do natychmiastowego zakupu. Na przykład duże meble:

  • Klienci, którzy szukają podobnych produktów w Google, zobaczą te reklamy z adnotacją „w sklepie” w wynikach wyszukiwania.
  • Klienci, którzy przeglądają asortyment sklepu na stronie wyników wyszukiwania Google, zobaczą te produkty z oznaczeniem „Dostępne na zamówienie”.

Aby wyświetlić te produkty, klienci mogą kliknąć reklamę lokalnego asortymentu produktów lub bezpłatne lokalne informacje o produkcie. Aby kupić produkt, użytkownicy mogą odwiedzić sklep stacjonarny, obejrzeć go, a następnie zamówić produkt z dostawą do domu lub możliwością odbioru w sklepie.

Informacje (Niemcy, Austria i Szwajcaria)

Jeśli wyświetlasz reklamy w Austrii i Niemczech i wybierzesz GHLSF, musisz przesłać stronę z informacjami.

Jeśli wyświetlasz reklamy w Szwajcarii, musisz przesłać stronę „Informacje” niezależnie od LsfType.

Dopóki adres URL strony z informacjami nie zostanie zweryfikowany, sprzedawcy korzystający z GHLSF nie mogą prosić Google o ręczną weryfikację asortymentu.

W przypadku wszystkich sprzedawców w tych 3 krajach usługa nie włącza funkcji bezpłatnych lokalnych informacji ani reklam lokalnego asortymentu produktów, dopóki strona z informacjami nie zostanie zatwierdzona.

Weryfikacja asortymentu

Weryfikacja asortymentu jest wymagana tylko w przypadku sprzedawców korzystających z GHLSF. Nie jest obsługiwana w przypadku typów MHLSF.

Zanim dodasz dane produktów i dane asortymentu (za pomocą metody accounts.products.localInventories.insert lub interfejsu Merchant Center) albo po ich dodaniu musisz zweryfikować swój kontakt. Podaj osobę kontaktową ds. weryfikacji asortymentu (imię i nazwisko oraz adres e-mail) za pomocą metody create lub update. Osoba kontaktowa otrzyma e-maila wysłanego przez Google i będzie mogła potwierdzić swój status, klikając przycisk w wiadomości.

Gdy to zrobisz, możesz poprosić o weryfikację asortymentu. Więcej informacji znajdziesz w artykule Informacje o weryfikacji asortymentu.

Osobę kontaktową możesz zmienić podczas procesu weryfikacji lub po jego zakończeniu za pomocą metody omnichannelSetting.update.

Po zakończeniu tego procesu Google sprawdzi dokładność podanych informacji.

Pobieranie ustawienia wielokanałowego

Aby pobrać konfigurację omnichannelSetting w danym kraju lub sprawdzić bieżący stan opinii, użyj metody omnichannelSettings.get.

Oto przykładowe żądanie:

GET https://merchantapi.googleapis.com/accounts/v1/accounts/{ACCOUNT_ID}/omnichannelSettings/{OMNICHANNEL_SETTING}

Zastąp następujące elementy:

  • {ACCOUNT_ID}: unikalny identyfikator konta Merchant Center.
  • {OMNICHANNEL_SETTING}: kod regionu kraju docelowego.

Stan ACTIVE oznacza, że opinia została zatwierdzona.

Jeśli stan to FAILED, rozwiąż problemy i wywołaj nową opinię, wywołując metodę omnichannelSetting.update.

Pole LFP tylko do odczytu pokazuje stan partnerstwa w zakresie lokalnych plików danych. Aby połączyć się z partnerstwem, użyj metody lfpProviders.linkLfpProvider.

Więcej informacji o sprawdzaniu stanów i ich znaczeniu znajdziesz w artykule Wyświetlanie stanu ustawienia wielokanałowego.

Wyświetlanie listy ustawień wielokanałowych

Aby pobrać wszystkie informacje omnichannelSetting dotyczące Twojego konta, użyj metody omnichannelSettings.list.

Oto przykładowy kod:

Java

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.ListOmnichannelSettingsRequest;
import com.google.shopping.merchant.accounts.v1.OmnichannelSetting;
import com.google.shopping.merchant.accounts.v1.OmnichannelSettingsServiceClient;
import com.google.shopping.merchant.accounts.v1.OmnichannelSettingsServiceClient.ListOmnichannelSettingsPagedResponse;
import com.google.shopping.merchant.accounts.v1.OmnichannelSettingsServiceSettings;
import shopping.merchant.samples.utils.Authenticator;
import shopping.merchant.samples.utils.Config;

/**
 * This class demonstrates how to get the list of omnichannel settings for a given Merchant Center
 * account
 */
public class ListOmnichannelSettingsSample {

  public static void omnichannelSettings(Config config) throws Exception {

    // Obtains OAuth token based on the user's configuration.
    GoogleCredentials credential = new Authenticator().authenticate();

    // Creates service settings using the credentials retrieved above.
    OmnichannelSettingsServiceSettings omnichannelSettingsServiceSettings =
        OmnichannelSettingsServiceSettings.newBuilder()
            .setCredentialsProvider(FixedCredentialsProvider.create(credential))
            .build();

    String accountId = config.getAccountId().toString();
    String parent = AccountName.newBuilder().setAccount(accountId).build().toString();

    // Calls the API and catches and prints any network failures/errors.
    try (OmnichannelSettingsServiceClient omnichannelSettingsServiceClient =
        OmnichannelSettingsServiceClient.create(omnichannelSettingsServiceSettings)) {
      ListOmnichannelSettingsRequest request =
          ListOmnichannelSettingsRequest.newBuilder().setParent(parent).build();

      System.out.println("Sending list omnichannel setting request:");
      ListOmnichannelSettingsPagedResponse response =
          omnichannelSettingsServiceClient.listOmnichannelSettings(request);

      int count = 0;

      // Iterates over all the entries in the response.
      for (OmnichannelSetting omnichannelSetting : response.iterateAll()) {
        System.out.println(omnichannelSetting);
        count++;
      }
      System.out.println(String.format("The following count of elements were returned: %d", count));
    } catch (Exception e) {
      System.out.println("An error has occured: ");
      System.out.println(e);
    }
  }

  public static void main(String[] args) throws Exception {
    Config config = Config.load();

    omnichannelSettings(config);
  }
}

PHP

use Google\ApiCore\ApiException;
use Google\Shopping\Merchant\Accounts\V1\Client\OmnichannelSettingsServiceClient;
use Google\Shopping\Merchant\Accounts\V1\ListOmnichannelSettingsRequest;

/**
 * This class demonstrates how to get the list of omnichannel settings for a
 * given Merchant Center account.
 */
class ListOmnichannelSettings
{
    /**
     * Helper to create the parent string.
     *
     * @param string $accountId The merchant account ID.
     * @return string The parent string in the format `accounts/{account}`.
     */
    private static function getParent(string $accountId): string
    {
        return sprintf('accounts/%s', $accountId);
    }

    /**
     * Lists the omnichannel settings for a given Merchant Center account.
     *
     * @param array $config The configuration file for authentication.
     */
    public static function listOmnichannelSettingsSample(array $config): void
    {
        // Obtains OAuth credentials from the configuration file.
        $credentials = Authentication::useServiceAccountOrTokenFile();

        // Creates a client.
        $omnichannelSettingsServiceClient = new OmnichannelSettingsServiceClient([
            'credentials' => $credentials
        ]);

        // Constructs the parent resource name.
        $parent = self::getParent($config['accountId']);

        // Creates the request.
        $request = new ListOmnichannelSettingsRequest(['parent' => $parent]);

        // Calls the API and prints the response.
        try {
            printf("Sending list omnichannel setting request:%s", PHP_EOL);
            $response = $omnichannelSettingsServiceClient->listOmnichannelSettings($request);

            $count = 0;
            // Iterates over all the omnichannel settings and prints them.
            foreach ($response->iterateAllElements() as $omnichannelSetting) {
                print $omnichannelSetting->serializeToJsonString(true) . PHP_EOL;
                $count++;
            }
            printf("The following count of elements were returned: %d%s", $count, PHP_EOL);
        } catch (ApiException $e) {
            printf("An error has occured: %s", $e->getMessage());
        }
    }

    /**
     * Executes the sample.
     */
    public function callSample(): void
    {
        $config = Config::generateConfig();
        self::listOmnichannelSettingsSample($config);
    }
}

// Runs the script.
$sample = new ListOmnichannelSettings();
$sample->callSample();

Python

from examples.authentication import configuration
from examples.authentication import generate_user_credentials
from google.shopping.merchant_accounts_v1 import ListOmnichannelSettingsRequest
from google.shopping.merchant_accounts_v1 import OmnichannelSettingsServiceClient


def list_omnichannel_settings(account_id: str) -> None:
  """Lists the omnichannel settings for a given Merchant Center account.

  Args:
      account_id: The ID of the Merchant Center account.
  """
  # Gets OAuth Credentials.
  credentials = generate_user_credentials.main()

  # Creates a client.
  client = OmnichannelSettingsServiceClient(credentials=credentials)

  # The parent account for which to list the settings.
  parent = f"accounts/{account_id}"

  # Creates the request.
  request = ListOmnichannelSettingsRequest(parent=parent)

  # Makes the request and catches and prints any error messages.
  try:
    print("Sending list omnichannel setting request:")
    response = client.list_omnichannel_settings(request=request)

    count = 0
    # Iterates over all the entries in the response.
    for omnichannel_setting in response:
      print(omnichannel_setting)
      count += 1
    print(f"The following count of elements were returned: {count}")
  except RuntimeError as e:
    print("An error has occured: ")
    print(e)


if __name__ == "__main__":
  # The ID of the account to get the omnichannel settings for.
  _ACCOUNT = configuration.Configuration().read_merchant_info()

  list_omnichannel_settings(_ACCOUNT)

Aktualizowanie ustawienia wielokanałowego

Aby zaktualizować konfigurację istniejącego ustawienia wielokanałowego, użyj metody omnichannelSettings.update.

Aby zaktualizować, musisz dodać funkcję, którą chcesz zaktualizować, do maski aktualizacji i wypełnić odpowiednie pola w polu omnichannelSetting w żądaniu aktualizacji. Możesz zaktualizować dowolne z tych pól:

  • lsfType
  • inStock
  • pickup
  • odo
  • about
  • inventoryVerification

Jeśli atrybut nie jest uwzględniony w masce aktualizacji, nie zostanie zaktualizowany.

Jeśli atrybut jest uwzględniony w masce aktualizacji, ale nie jest ustawiony w żądaniu, zostanie wyczyszczony.

Ten przykładowy kod pokazuje, jak zaktualizować pole weryfikacji asortymentu.

Java

import com.google.api.gax.core.FixedCredentialsProvider;
import com.google.auth.oauth2.GoogleCredentials;
import com.google.protobuf.FieldMask;
import com.google.shopping.merchant.accounts.v1.InventoryVerification;
import com.google.shopping.merchant.accounts.v1.OmnichannelSetting;
import com.google.shopping.merchant.accounts.v1.OmnichannelSettingName;
import com.google.shopping.merchant.accounts.v1.OmnichannelSettingsServiceClient;
import com.google.shopping.merchant.accounts.v1.OmnichannelSettingsServiceSettings;
import com.google.shopping.merchant.accounts.v1.UpdateOmnichannelSettingRequest;
import shopping.merchant.samples.utils.Authenticator;
import shopping.merchant.samples.utils.Config;

/**
 * This class demonstrates how to update an omnichannel setting for a given Merchant Center account
 * in a given country
 */
public class UpdateOmnichannelSettingSample {

  public static void updateOmnichannelSettings(
      Config config, String regionCode, String contact, String email) throws Exception {

    // Obtains OAuth token based on the user's configuration.
    GoogleCredentials credential = new Authenticator().authenticate();

    // Creates service settings using the credentials retrieved above.
    OmnichannelSettingsServiceSettings omnichannelSettingsServiceSettings =
        OmnichannelSettingsServiceSettings.newBuilder()
            .setCredentialsProvider(FixedCredentialsProvider.create(credential))
            .build();

    // Calls the API and catches and prints any network failures/errors.
    try (OmnichannelSettingsServiceClient omnichannelSettingsServiceClient =
        OmnichannelSettingsServiceClient.create(omnichannelSettingsServiceSettings)) {
      String accountId = config.getAccountId().toString();
      String name =
          OmnichannelSettingName.newBuilder()
              .setAccount(accountId)
              .setOmnichannelSetting(regionCode)
              .build()
              .toString();

      OmnichannelSetting omnichannelSetting =
          OmnichannelSetting.newBuilder()
              .setName(name)
              .setInventoryVerification(
                  InventoryVerification.newBuilder()
                      .setContact(contact)
                      .setContactEmail(email)
                      .build())
              .build();
      FieldMask fieldMask = FieldMask.newBuilder().addPaths("inventory_verification").build();
      UpdateOmnichannelSettingRequest request =
          UpdateOmnichannelSettingRequest.newBuilder()
              .setOmnichannelSetting(omnichannelSetting)
              .setUpdateMask(fieldMask)
              .build();

      System.out.println("Sending update omnichannel setting request:");
      OmnichannelSetting response =
          omnichannelSettingsServiceClient.updateOmnichannelSetting(request);

      System.out.println("Updated Omnichannel Setting below:");
      System.out.println(response);
    } catch (Exception e) {
      System.out.println("An error has occured: ");
      System.out.println(e);
    }
  }

  public static void main(String[] args) throws Exception {
    Config config = Config.load();

    // The country which you're targeting at.
    String regionCode = "{REGION_CODE}";
    // The name of the inventory verification contact you want to update.
    String contact = "{NAME}";
    // The address of the inventory verification email you want to update.
    String email = "{EMAIL}";

    updateOmnichannelSettings(config, regionCode, contact, email);
  }
}

PHP

use Google\ApiCore\ApiException;
use Google\Protobuf\FieldMask;
use Google\Shopping\Merchant\Accounts\V1\Client\OmnichannelSettingsServiceClient;
use Google\Shopping\Merchant\Accounts\V1\InventoryVerification;
use Google\Shopping\Merchant\Accounts\V1\OmnichannelSetting;
use Google\Shopping\Merchant\Accounts\V1\UpdateOmnichannelSettingRequest;

/**
 * This class demonstrates how to update an omnichannel setting for a given
 * Merchant Center account in a given country.
 */
class UpdateOmnichannelSetting
{
    /**
     * Helper to create the name string.
     *
     * @param string $accountId The merchant account ID.
     * @param string $regionCode The region code of the setting.
     * @return string The name string in the format
     *     `accounts/{account}/omnichannelSettings/{omnichannelSetting}`.
     */
    private static function getName(string $accountId, string $regionCode): string
    {
        return sprintf('accounts/%s/omnichannelSettings/%s', $accountId, $regionCode);
    }

    /**
     * Updates an omnichannel setting for a given Merchant Center account.
     *
     * @param array $config The configuration file for authentication.
     * @param string $regionCode The country of the omnichannel setting.
     * @param string $contact The name of the inventory verification contact.
     * @param string $email The email of the inventory verification contact.
     */
    public static function updateOmnichannelSettingSample(
        array $config,
        string $regionCode,
        string $contact,
        string $email
    ): void {
        // Obtains OAuth credentials from the configuration file.
        $credentials = Authentication::useServiceAccountOrTokenFile();

        // Creates a client.
        $omnichannelSettingsServiceClient = new OmnichannelSettingsServiceClient([
            'credentials' => $credentials
        ]);

        // Constructs the resource name.
        $name = self::getName($config['accountId'], $regionCode);

        // Creates the omnichannel setting with the updated fields.
        $omnichannelSetting = new OmnichannelSetting([
            'name' => $name,
            'inventory_verification' => new InventoryVerification([
                'contact' => $contact,
                'contact_email' => $email
            ])
        ]);

        // Creates the field mask to specify which fields to update.
        $fieldMask = new FieldMask([
            'paths' => ['inventory_verification']
        ]);

        // Creates the request.
        $request = new UpdateOmnichannelSettingRequest([
            'omnichannel_setting' => $omnichannelSetting,
            'update_mask' => $fieldMask
        ]);

        // Calls the API and prints the response.
        try {
            printf("Sending update omnichannel setting request:%s", PHP_EOL);
            $response = $omnichannelSettingsServiceClient->updateOmnichannelSetting($request);
            printf("Updated Omnichannel Setting below:%s", PHP_EOL);
            print $response->serializeToJsonString(true) . PHP_EOL;
        } catch (ApiException $e) {
            printf("An error has occured: %s", $e->getMessage());
        }
    }

    /**
     * Executes the sample.
     */
    public function callSample(): void
    {
        $config = Config::generateConfig();
        // The country which you're targeting.
        $regionCode = '{REGION_CODE}';
        // The name of the inventory verification contact you want to update.
        $contact = '{NAME}';
        // The address of the inventory verification email you want to update.
        $email = '{EMAIL}';
        self::updateOmnichannelSettingSample($config, $regionCode, $contact, $email);
    }
}

// Runs the script.
$sample = new UpdateOmnichannelSetting();
$sample->callSample();

Python

from examples.authentication import configuration
from examples.authentication import generate_user_credentials
from google.protobuf import field_mask_pb2
from google.shopping.merchant_accounts_v1 import InventoryVerification
from google.shopping.merchant_accounts_v1 import OmnichannelSetting
from google.shopping.merchant_accounts_v1 import OmnichannelSettingsServiceClient
from google.shopping.merchant_accounts_v1 import (
    UpdateOmnichannelSettingRequest,
)


def update_omnichannel_setting(
    account_id: str, region_code: str, contact: str, email: str
) -> None:
  """Updates an omnichannel setting for a given Merchant Center account.

  Args:
      account_id: The ID of the Merchant Center account.
      region_code: The country for which you're updating the setting.
      contact: The name of the inventory verification contact.
      email: The email of the inventory verification contact.
  """
  # Gets OAuth Credentials.
  credentials = generate_user_credentials.main()

  # Creates a client.
  client = OmnichannelSettingsServiceClient(credentials=credentials)

  # The name of the omnichannel setting to update.
  name = f"accounts/{account_id}/omnichannelSettings/{region_code}"

  # Creates an omnichannel setting with the updated values.
  omnichannel_setting = OmnichannelSetting()
  omnichannel_setting.name = name
  omnichannel_setting.inventory_verification = InventoryVerification(
      contact=contact, contact_email=email
  )

  # Creates a field mask to specify which fields to update.
  field_mask = field_mask_pb2.FieldMask(paths=["inventory_verification"])

  # Creates the request.
  request = UpdateOmnichannelSettingRequest(
      omnichannel_setting=omnichannel_setting, update_mask=field_mask
  )

  # Makes the request and catches and prints any error messages.
  try:
    print("Sending update omnichannel setting request:")
    response = client.update_omnichannel_setting(request=request)
    print("Updated Omnichannel Setting below:")
    print(response)
  except RuntimeError as e:
    print("An error has occured: ")
    print(e)


if __name__ == "__main__":
  # The ID of the account to get the omnichannel settings for.
  _ACCOUNT = configuration.Configuration().read_merchant_info()

  # The country which you're targeting.
  _REGION_CODE = "{REGION_CODE}"
  # The name of the inventory verification contact you want to update.
  _CONTACT = "{NAME}"
  # The address of the inventory verification email you want to update.
  _EMAIL = "{EMAIL}"

  update_omnichannel_setting(_ACCOUNT, _REGION_CODE, _CONTACT, _EMAIL)

Przesyłanie prośby o weryfikację asortymentu

omnichannelSettings.requestInventoryVerification dotyczy tylko sprzedawców korzystających z GHLSF.

Zanim wywołasz ten RPC, musisz wykonać te czynności:

  • Prześlij dane produktów i asortymentu.
  • Zweryfikuj osobę kontaktową ds. weryfikacji asortymentu.
  • W przypadku sprzedawców w Austrii, Niemczech lub Szwajcarii prześlij stronę About do sprawdzenia.

Aby sprawdzić, czy się kwalifikujesz, wywołaj metodę omnichannelSettings.get i sprawdź omnichannelSetting.inventoryVerification.state. Jeśli wyświetla się INACTIVE, możesz wywołać metodę omnichannelSettings.requestInventoryVerification.

Java

import com.google.api.gax.core.FixedCredentialsProvider;
import com.google.auth.oauth2.GoogleCredentials;
import com.google.shopping.merchant.accounts.v1.OmnichannelSettingName;
import com.google.shopping.merchant.accounts.v1.OmnichannelSettingsServiceClient;
import com.google.shopping.merchant.accounts.v1.OmnichannelSettingsServiceSettings;
import com.google.shopping.merchant.accounts.v1.RequestInventoryVerificationRequest;
import com.google.shopping.merchant.accounts.v1.RequestInventoryVerificationResponse;
import shopping.merchant.samples.utils.Authenticator;
import shopping.merchant.samples.utils.Config;

/**
 * This class demonstrates how to request inventory verification for a given Merchant Center account
 * in a given country
 */
public class RequestInventoryVerificationSample {

  public static void requestInventoryVerification(Config config, String regionCode)
      throws Exception {

    // Obtains OAuth token based on the user's configuration.
    GoogleCredentials credential = new Authenticator().authenticate();

    // Creates service settings using the credentials retrieved above.
    OmnichannelSettingsServiceSettings omnichannelSettingsServiceSettings =
        OmnichannelSettingsServiceSettings.newBuilder()
            .setCredentialsProvider(FixedCredentialsProvider.create(credential))
            .build();

    // Calls the API and catches and prints any network failures/errors.
    try (OmnichannelSettingsServiceClient omnichannelSettingsServiceClient =
        OmnichannelSettingsServiceClient.create(omnichannelSettingsServiceSettings)) {
      String accountId = config.getAccountId().toString();
      String name =
          OmnichannelSettingName.newBuilder()
              .setAccount(accountId)
              .setOmnichannelSetting(regionCode)
              .build()
              .toString();
      RequestInventoryVerificationRequest request =
          RequestInventoryVerificationRequest.newBuilder().setName(name).build();

      System.out.println("Sending request inventory verification request:");
      RequestInventoryVerificationResponse response =
          omnichannelSettingsServiceClient.requestInventoryVerification(request);

      System.out.println("Omnichannel Setting after inventory verification request below:");
      System.out.println(response);
    } catch (Exception e) {
      System.out.println("An error has occured: ");
      System.out.println(e);
    }
  }

  public static void main(String[] args) throws Exception {
    Config config = Config.load();

    // The country which you're targeting at.
    String regionCode = "{REGION_CODE}";

    requestInventoryVerification(config, regionCode);
  }
}

Wyświetlanie stanu ustawienia wielokanałowego

Aby sprawdzić stan opinii dotyczących rejestracji w reklamach lokalnego asortymentu produktów, sprawdź ReviewState w przypadku odpowiednich atrybutów omnichannelSetting zwracanych przez omnichannelSettings.get lub omnichannelSettings.list metody.

Pole ReviewState dotyczy wszystkich opinii dotyczących rejestracji z wyjątkiem procesu weryfikacji asortymentu i może przyjmować te wartości:

  • ACTIVE: zatwierdzono.
  • FAILED: odrzucono.
  • RUNNING: w trakcie sprawdzania.
  • ACTION_REQUIRED: ta wartość występuje tylko w przypadku InStock.state w przypadku sprzedawców korzystających z `GHLSF`. Oznacza to, że aby reklamy lokalnego asortymentu produktów mogły się wyświetlać, musisz poprosić o weryfikację asortymentu.

InventoryVerification.State może przyjmować te wartości:

  • SUCCEEDED: zatwierdzono.
  • INACTIVE: możesz poprosić o weryfikację asortymentu.
  • RUNNING: w trakcie sprawdzania.
  • SUSPENDED: weryfikacja asortymentu nie powiodła się zbyt wiele razy (zwykle 5). Musisz poczekać, zanim ponownie poprosisz o weryfikację.
  • ACTION_REQUIRED: zanim poprosisz o weryfikację asortymentu, musisz wykonać dodatkowe działania.

Rozwiązywanie problemów związanych z interfejsem Omnichannel Settings API

W tej sekcji opisujemy, jak rozwiązywać typowe problemy.

Tworzenie ustawienia wielokanałowego

  • Upewnij się, że ustawisz zarówno LsfType, jak i RegionCode.
  • Jeśli wybierzesz GHLSF, podaj puste pole InStock w żądaniu.
  • Jeśli wybierzesz typy lokalnej witryny sklepowej sprzedawcy, podaj co najmniej 1 identyfikator URI w polu InStock lub Pickup.

Aktualizowanie ustawienia wielokanałowego

Metoda aktualizacji tego zasobu wymaga dodatkowych reguł:

  • Nie możesz modyfikować kodu regionu.
  • Nie możesz wprowadzać zmian, gdy funkcja reklam lokalnego asortymentu produktów lub bezpłatnych lokalnych informacji jest uruchomiona lub została zatwierdzona.
  • Jeśli zmieniasz typy lokalnej witryny sklepowej sprzedawcy na GHLSF, a wcześniej skonfigurowano InStock i Pickup, musisz uwzględnić je w masce aktualizacji wraz z aktualizacją LsfType.

Jeśli na przykład wcześniej zastosowano MHLSF_BASIC i Pickup, a zostały one odrzucone, możesz przejść na GHLSF, wysyłając takie żądanie:

PATCH https://merchantapi.googleapis.com/accounts/v1/accounts/{ACCOUNT_ID}/omnichannelSettings/{REGION_CODE}?update_mask=lsf_type,in_stock,pickup

{
  "lsfType": "GHLSF",
  "inStock": {},
}

Zastąp następujące elementy:

  • {ACCOUNT_ID}: unikalny identyfikator konta Merchant Center.
  • {REGION_CODE}: kod regionu zdefiniowany przez CLDR.

Przesyłanie prośby o weryfikację asortymentu

Jeśli pomimo zaktualizowania plików danych o produktach lub asortymentu i potwierdzenia kontaktu InventoryVerification.state ma inną wartość niż INACTIVE:

  • W przypadku sprzedawców w Austrii, Niemczech i Szwajcarii: upewnij się, że strona z informacjami została sprawdzona.
  • Nastąpi opóźnienie wynoszące około 48 godzin.
  • W przypadku powtarzających się błędów sprawdzania asortymentu (ponad 5) usługa wymusza 30-dniowy okres oczekiwania, zanim zezwoli na kolejne żądanie. Jeśli chcesz poprosić o wcześniejszy zwrot środków, skontaktuj się z zespołem pomocy Google.

Więcej informacji

Więcej informacji znajdziesz w Centrum pomocy reklam lokalnego asortymentu produktów i bezpłatnych lokalnych informacji.