您可以使用 Accounts API 管理 Merchant Center 账号与其他服务提供商之间的关系。关系是一种正式的连接,可让提供商向您的企业提供特定服务。服务定义了授予提供商的权限和功能,例如产品管理或广告系列管理。例如,将 Merchant Center 账号与 Google Ads 账号相关联后,Google Ads 账号就可以使用您的商品数据来投放广告系列。
关系由以下属性组成:
- 接受服务的 Merchant Center 账号
- 服务提供商
- 提供给 Merchant Center 账号的服务或一组服务
别名
服务提供商可以将别名与他们所服务的账号相关联(这相当于 Content API for Shopping 中账号资源中存在的 seller_id 字段)。可以使用 AccountRelationship 资源中的可选 account_id_alias 字段分配别名,该别名用作自定义标识符。别名必须包含 1 到 50 个字符,且只能包含 ASCII 字母、十进制数字、连字符、下划线、英文句点或波形符 ([A-Za-z0-9_~.-]{1,50})。
使用别名访问账号的网址结构为 GET /accounts/v1/accounts/{provider}~{account_id_alias}。
服务
在 Accounts API 中,账号可以接收以下服务。您可以在创建账号期间添加许多此类服务。
账号汇总:此服务会将高级账号与其他账号相关联,从而授予高级账号不受限制的完整访问权限。 它通常适用于需要集中控制嵌套账号的购物平台、多品牌零售商或国际零售商。 如果您是电子商务平台或渠道合作伙伴,我们建议您改用
accountManagement。使用账号汇总功能创建账号时,必须省略externalAccountId。广告系列管理:此服务用于模拟 Merchant Center 账号与 Google Ads 账号之间的关联,使 Google Ads 账号能够访问运行广告系列所需的商品和账号数据。在这种情况下,服务提供商为
GOOGLE_ADS,externalAccountId是 Google Ads 账号的 ID。此服务也可向现有账号提议。
购物比较:表示与运营 Merchant Center 账号的购物比较服务 (CSS) 的关系。
本地商家信息管理:表示与商店经理的关系,用于使用 Google 商家资料管理本地产品目录和商家信息。
账号管理:此服务可让提供方对 Merchant Center 账号执行管理操作,例如配置账号设置、管理用户或更新商家信息。商家还可以限制授予的访问权限。在创建账号期间使用时,此服务会创建一个与提供方相关联的账号,这是电子商务平台和渠道合作伙伴的推荐方法。也可以向现有账号提出建议。
产品管理:此服务允许提供商管理产品和相关功能,例如数据源和规则。如果在创建账号时添加,通常会与
accountManagement或accountAggregation结合使用。此服务也可向现有账号提议。
握手
如需建立服务,提供服务的账号和接收服务的账号都必须授权连接。此授权过程称为握手。
握手过程分为两步:
- 一方提议建立服务关联。
- 对方批准或拒绝提案。
提案一旦被接受,服务即获得批准并被视为完全确立。授予服务提供商的任何访问权限现在都将授予符合条件的用户(请参阅下文中的访问权限)。
请注意,创建、拒绝或批准提案的用户必须对发起流程的账号拥有 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权限。请注意,未来此权限将仅限于与产品相关的访问权限。
关系如何适用于第三方平台
如果您是代表其他商家管理账号的第三方平台,下表显示了不同的概念如何映射到您的账号结构:
- 服务提供商:您的高级账号。
- 接受服务的账号:代表您管理的商家的 Merchant Center 账号。
- 服务:
accountManagement:建议电子商务平台和渠道合作伙伴使用此服务代表商家创建新账号。它会创建一个由商家拥有的账号,并与您相关联以供您管理。这与此用例的首选 Merchant Center 结构一致。accountAggregation:此服务会将您的高级账号与其他账号相关联。虽然支持,但不建议电子商务平台和渠道合作伙伴使用。