管理帳戶關係

你可以使用 Accounts API 管理 Merchant Center 帳戶與其他服務供應商之間的關係。關係是正式連結,可讓供應商為您的商家提供特定服務。服務會定義授予供應商的權限和功能,例如產品管理或廣告活動管理。舉例來說,將 Merchant Center 帳戶連結至 Google Ads 帳戶後,Google Ads 帳戶就能使用你的產品資料放送廣告活動。

關係由下列屬性組成:

  • 接收服務的 Merchant Center 帳戶
  • 服務供應商
  • 提供給 Merchant Center 帳戶的服務或一組服務

別名

服務供應商可以將別名與他們服務的帳戶建立關聯 (這相當於 Content API for Shopping 中帳戶資源的 seller_id 欄位)。別名可使用 AccountRelationship 資源中的選用 account_id_alias 欄位指派,並做為自訂 ID。別名必須由 1 至 50 個字元組成,且只能使用 ASCII 字母、十進位數字、連字號、底線、半形句號或波浪號 ([A-Za-z0-9_~.-]{1,50})。

如要使用別名存取帳戶,網址結構為 GET /accounts/v1/accounts/{provider}~{account_id_alias}

服務

在帳戶 API 中,帳戶可接收下列服務。您可以在建立帳戶時新增許多這類服務。

  • 帳戶彙整:這項服務會將進階帳戶連結至其他帳戶,授予進階帳戶完整且不受限制的存取權。通常由市集、多品牌零售商或需要集中控管巢狀帳戶的國際零售商使用。如果你是電子商務平台或管道合作夥伴,建議改用 accountManagement。使用帳戶匯總功能建立帳戶時,請省略 externalAccountId

  • 廣告活動管理:這項服務會模擬 Merchant Center 帳戶與 Google Ads 帳戶之間的連結,讓 Google Ads 帳戶存取放送廣告活動所需的產品和帳戶資料。在本例中,服務供應商為 GOOGLE_ADS,而 externalAccountId 則是 Google Ads 帳戶的 ID。這項服務也可提供給現有帳戶。

  • 購物比較:這代表與經營 Merchant Center 帳戶的購物比較服務 (CSS) 之間的關係。

  • 店面資訊管理:這代表與商店管理員的關係,可使用 Google 商家檔案管理店面商品目錄和資訊。

  • 帳戶管理:這項服務可讓供應商對 Merchant Center 帳戶執行管理動作,例如設定帳戶設定、管理使用者或更新商家資訊。商家也可以限制授予的存取權。在建立帳戶時使用,這項服務會建立連結至供應商的帳戶,建議電子商務平台和通路合作夥伴採用這種做法。也可以提議將其新增至現有帳戶。

  • 產品管理:供應商可透過這項服務管理產品和相關功能,例如資料來源和規則。在帳戶建立期間新增時,通常會與 accountManagementaccountAggregation 搭配使用。這項服務也可提供給現有帳戶。

畫面中有兩個人在握手

如要建立服務,提供服務的帳戶和接收服務的帳戶都必須授權連線。這項授權程序稱為「交握」。

交握程序分為兩個步驟:

  1. 其中一方提議服務連結。
  2. 對方核准或拒絕提案。

提案獲得接受後,服務即獲准,並視為完全建立。授予服務供應商的任何存取權,現在都將授予符合資格的使用者 (請參閱下方的存取權)。

請注意,建立、拒絕或核准提案的使用者,必須對啟動程序的帳戶擁有 ADMIN 存取權。因此,如果服務供應商提議提供服務,提出提議的使用者必須是服務供應商帳戶的 ADMIN,而接受或拒絕提議的使用者必須是接收帳戶的 ADMIN

下列範例說明如何提議帳戶服務:

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.AccountService;
import com.google.shopping.merchant.accounts.v1.AccountServicesServiceClient;
import com.google.shopping.merchant.accounts.v1.AccountServicesServiceSettings;
import com.google.shopping.merchant.accounts.v1.ProductsManagement;
import com.google.shopping.merchant.accounts.v1.ProposeAccountServiceRequest;
import shopping.merchant.samples.utils.Authenticator;

/** This class demonstrates how to propose a service to an existing Merchant Center account. */
public class ProposeServiceSample {

  public static void proposeService(long accountId, long providerId, String externalAccountId)
      throws Exception {

    // Obtains OAuth token based on the user's configuration.
    // The user that authenticates should have access to the account.
    GoogleCredentials credential = new Authenticator().authenticate();

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

    // Calls the API and catches and prints any network failures/errors.
    try (AccountServicesServiceClient accountServicesServiceClient =
        AccountServicesServiceClient.create(accountServicesServiceSettings)) {

      // The service to be proposed.
      // This sample shows how to propose product management.
      // For more information about the different services, see:
      // https://developers.google.com/merchant/api/guides/accounts/services
      AccountService accountService =
          AccountService.newBuilder()
              .setProductsManagement(ProductsManagement.newBuilder().build())
              .setExternalAccountId(externalAccountId)
              .build();

      String accountName =
          AccountName.newBuilder().setAccount(String.valueOf(accountId)).build().toString();

      ProposeAccountServiceRequest request =
          ProposeAccountServiceRequest.newBuilder()
              .setParent(accountName)
              .setProvider("accounts/" + providerId)
              .setAccountService(accountService)
              .build();

      System.out.println("Sending Propose Service request:");
      AccountService response = accountServicesServiceClient.proposeAccountService(request);

      System.out.println("Proposed Service below");
      System.out.println(response);
    } catch (Exception e) {
      System.out.println(e);
    }
  }

  public static void main(String[] args) throws Exception {
    // The ID of the account to propose the service to.
    long accountId = 123L;
    // This is the provider ID of the e-commerce platform.
    long providerId = 456L;
    // An external ID that uniquely identifies the account service.
    String externalAccountId = "ext-acc-id-123";
    proposeService(accountId, providerId, externalAccountId);
  }
}

PHP

require_once __DIR__ . '/../../../../vendor/autoload.php';
require_once __DIR__ . '/../../../Authentication/Authentication.php';
require_once __DIR__ . '/../../../Authentication/Config.php';

use Google\ApiCore\ApiException;
use Google\Shopping\Merchant\Accounts\V1\AccountAggregation;
use Google\Shopping\Merchant\Accounts\V1\AccountService;
use Google\Shopping\Merchant\Accounts\V1\Client\AccountServicesServiceClient;
use Google\Shopping\Merchant\Accounts\V1\ProposeAccountServiceRequest;

/**
 * This class demonstrates how to propose an account service.
 */
class ProposeAccountServiceSample
{
    /**
     * A helper function to create the account name string.
     *
     * @param string $accountId The ID of the account.
     *
     * @return string The account name has the format: `accounts/{account_id}`
     */
    private static function toAccountName(string $accountId): string
    {
        return sprintf('accounts/%s', $accountId);
    }

    /**
     * Proposes a new account service.
     *
     * @param array $config The configuration data used for authentication and
     *     getting the account ID.
     * @param string $providerId The ID of the provider account.
     */
    public static function proposeAccountService(
        array $config,
        string $providerId
    ): void {
        // Gets the OAuth credentials to make the request.
        $credentials = Authentication::useServiceAccountOrTokenFile();

        // Creates options containing credentials for the client to use.
        $options = ['credentials' => $credentials];

        // Creates a client.
        $accountServicesServiceClient = new AccountServicesServiceClient($options);

        // Calls the API and catches and prints any network failures/errors.
        try {
            $accountAggregation = new AccountAggregation();
            $accountService = (new AccountService())
                ->setAccountAggregation($accountAggregation);

            $request = (new ProposeAccountServiceRequest())
                ->setParent(self::toAccountName($config['accountId']))
                ->setProvider(self::toAccountName($providerId))
                ->setAccountService($accountService);

            print "Sending Propose AccountService request\n";
            $response = $accountServicesServiceClient->proposeAccountService($request);
            print "Proposed AccountService below\n";
            print $response->serializeToJsonString(true) . PHP_EOL;
        } catch (ApiException $e) {
            printf("An error has occurred: %s%s", $e->getMessage(), PHP_EOL);
        }
    }

    /**
     * Helper to execute the sample.
     */
    public function callSample(): void
    {
        $config = Config::generateConfig();

        // Update this with the Merchant Center provider ID you want to get the
        // relationship for.
        $providerId = 111;
        self::proposeAccountService($config, $providerId);
    }
}

// Run the script
$sample = new ProposeAccountServiceSample();
$sample->callSample();

Python

"""This class demonstrates how to propose an account service."""

from examples.authentication import configuration
from examples.authentication import generate_user_credentials
from google.shopping.merchant_accounts_v1 import AccountAggregation
from google.shopping.merchant_accounts_v1 import AccountService
from google.shopping.merchant_accounts_v1 import AccountServicesServiceClient
from google.shopping.merchant_accounts_v1 import ProposeAccountServiceRequest

_ACCOUNT = configuration.Configuration().read_merchant_info()
_PARENT = f"accounts/{_ACCOUNT}"


def propose_account_service(provider_id: int) -> None:
  """Proposes an account service.

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

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

  # Creates the provider resource name from the provider ID.
  provider = f"accounts/{provider_id}"

  # Creates an AccountService object.
  # For this request, only `account_aggregation` is needed.
  account_service = AccountService()
  account_service.account_aggregation = AccountAggregation()

  # Creates the request.
  request = ProposeAccountServiceRequest(
      parent=_PARENT,
      provider=provider,
      account_service=account_service,
  )

  # Makes the request and catches and prints any error messages.
  try:
    print("Sending Propose AccountService request")
    response = client.propose_account_service(request=request)
    print("Proposed AccountService below")
    print(response)
  except RuntimeError as e:
    print(e)


if __name__ == "__main__":
  # Update this with the Merchant Center provider ID you want to get the
  # relationship for.
  provider_id_ = 111
  propose_account_service(provider_id_)

服務專屬交握行為

以下說明各項服務的具體握手需求:

  • 帳戶匯總:這項服務只能在建立帳戶時一併設定。服務供應商應為進階帳戶,且由於進階帳戶使用者擁有所建立帳戶的完整 ADMIN 存取權,因此服務會自動獲得核准。

  • 購物比較:使用 createAndConfigure 建立帳戶時,系統會自動核准這項服務。

  • 廣告活動管理:雖然這項作業會遵循正常的交握程序,但提案是在一個系統 (例如 Google Ads) 中進行,核准則是在另一個系統 (例如 Merchant Center 或透過 Merchant API) 中完成。

  • 在地商家資訊管理:這項服務會在專用方法中提議交握,並在其他系統 (例如 Google 商家檔案) 中完成核准。如需詳細步驟,請參閱連結 Google 商家檔案指南

  • 帳戶管理:使用 propose 時,這項服務適用於一般交握程序。如果是在建立帳戶時使用 createAndConfigure 新增服務,系統會自動核准。

  • 產品管理:這項服務適用一般握手程序 (由一方提議,另一方接受)。

存取權

每種服務類型都會為服務供應商的使用者提供特定層級的存取權,方便他們管理受服務的帳戶:

  • 帳戶匯總:這項服務提供完整的ADMIN權限。

  • 廣告活動管理:這項服務提供受限的存取權,允許相關聯的 Google Ads 帳戶存取產品和基本帳戶資訊。

  • 購物比較:這項服務預設提供完整的ADMIN權利。不過,商家可以在 Merchant Center 中限制授予的存取權。

  • 在地商家資訊管理:這項服務不提供直接存取權。而是讓產品資訊與 Merchant Center 帳戶同步。

重要事項:下列服務類型所述的存取權僅適用於已核准的服務供應商。如果您是服務供應商,並想使用這項功能,請與我們的支援團隊聯絡。如果先前已獲准在 Content API for Shopping 中使用 accounts.link 方法管理產品,即可在 Merchant API 中使用這項服務,不必再次申請核准。

  • 帳戶管理:這項服務預設提供完整ADMIN權限。

  • 產品管理:這項服務提供完整的ADMIN權利。請注意,日後這項權限將僅限於產品相關存取權。

關係如何適用於第三方平台

如果您是第三方平台,代表其他商家管理帳戶,下表說明不同概念如何對應至您的帳戶結構:

  1. 服務供應商:您的進階帳戶
  2. 接收服務的帳戶:代表你管理業務的 Merchant Center 帳戶。
  3. 服務
    • accountManagement:建議電子商務平台和管道合作夥伴使用這項服務,代表商家建立新帳戶。系統會建立商家擁有的帳戶,並連結至您以供管理。這與此使用案例的偏好 Merchant Center 結構一致。
    • accountAggregation:這項服務會將進階帳戶連結至其他帳戶。雖然支援,但不建議電子商務平台和通路合作夥伴使用。

如要進一步瞭解如何設定進階帳戶,以及如何連結至新的 Merchant Center 帳戶,請參閱「建立帳戶」。