与其他素材资源不同,地址素材资源是在您创建素材资源集后由 Google Ads API 自动创建的。首先,创建地址同步素材资源集并将其附加到客户。然后,如果您需要为广告系列或广告组选择素材资源集中的一部分地址素材资源,请创建营业地点组素材资源集并将其附加到广告系列或广告组。
创建地址同步素材资源集并将其附加到客户
- 创建地址同步素材资源集。
- 使用
CustomerAssetSetService将其附加到客户。
创建地址同步素材资源集
- 创建新的
AssetSet。- 将
type设置为LOCATION_SYNC。 - 将
location_set设置为新的LocationSet。
- 将
在新的
LocationSet中,- 根据您的使用情形设置
location_ownership_type:- 如果您拥有商家营业地点,请将其设置为
BUSINESS_OWNER。 - 如果您不拥有商家营业地点,但在此销售产品,请将其设置为
AFFILIATE。
- 如果您拥有商家营业地点,请将其设置为
根据您的使用情形设置
sourceoneof 字段:如果您想与 Google 商家资料账号中的 营业地点同步,请设置
business_profile_location_set。当您创建
BusinessProfileLocationSet以将 Google Ads 与 Google 商家资料账号相关联时,必须在http_authorization_token字段中提供 OAuth 2.0 访问令牌。此令牌可证明您授权 Google Ads 访问指定 Google 商家资料中的营业地点数据。该令牌必须满足以下要求:
- 必须为 Google 账号(用户账号或服务账号)生成,该账号的电子邮件地址在
BusinessProfileLocationSet的email_address字段中提供。 - 此账号必须具有足够的权限来读取 Google 商家资料中的商家营业地点。
- 必须使用
https://www.googleapis.com/auth/business.manage范围获取 OAuth 2.0 令牌。
如需详细了解如何生成 OAuth 2.0 访问 令牌,请参阅 使用 OAuth 2.0 访问 Google API。
- 必须为 Google 账号(用户账号或服务账号)生成,该账号的电子邮件地址在
如果您想与指定连锁 ID 中的营业地点同步,请设置
chain_location_set。如果您想使用 地点 ID手动添加营业地点,请设置
maps_location_set。
- 根据您的使用情形设置
完成这些步骤后,Google Ads API 会生成 地址
素材资源 ,并将其添加到您创建的地址同步素材资源集中,这与您使用
AssetSetAssetService手动执行此操作类似。除非您想手动将它们添加到静态营业地点组素材资源集中,否则无需对其进行操作。
对于一个客户,只能存在一个处于活动状态的地址同步素材资源集
(status 为
ENABLED)。如果您需要创建其他类型的地址同步素材资源集,请先移除现有素材资源集。
将地址同步素材资源集附加到客户
使用
CustomerAssetSetService.MutateCustomerAssetSets
将上一部分中的地址同步素材资源集附加到客户。
(可选)创建营业地点组素材资源集并将其附加到广告系列或广告组
只有在您需要选择一部分地址素材资源时,才需要营业地点组 素材资源集。这是因为广告系列和广告组会从客户一级沿用地址素材资源。
营业地点组素材资源集包含地址同步 素材资源集的一部分地址素材资源。您可以利用 Google 商家资料(例如按标签过滤)或连锁 ID 和连锁营业地点的某些功能,动态创建营业地点组素材资源集。或者,您也可以静态创建营业地点组素材资源集。
- 创建营业地点组素材资源集。营业地点组素材资源集可以是动态 的,也可以是静态 的。
- 根据您的需要,使用 将素材资源集附加到广告系列,或使用 将素材资源集附加到广告组 。
- (可选)将之前生成的素材资源添加到新创建的静态 营业地点组素材资源集中。
对于给定的客户,您可以创建多个动态或静态营业地点组素材资源集。
创建营业地点组素材资源集
创建一个新的 AssetSet,并将
location_group_parent_asset_set_id设置为之前创建的
地址同步素材资源集的 ID。
然后,根据您要创建动态还是静态营业地点组素材资源集,设置一些字段。
动态素材资源集
根据您在 LocationSet 中设置的字段,按照以下规则设置字段:
| 如果您设置了以下字段 | 然后将类型设置为 | 并将此字段设置为 asset_set_source oneof 字段 |
|---|---|---|
business_profile_location_set |
BUSINESS_PROFILE_DYNAMIC_LOCATION_GROUP |
business_profile_location_group |
chain_location_set |
CHAIN_DYNAMIC_LOCATION_GROUP |
chain_location_group |
如果您在创建地址同步素材资源
集时设置了 maps_location_set,则无法创建动态营业地点
组素材资源集。这是因为您已通过地点 ID 手动添加了营业地点,并且没有可用于此类营业地点的过滤功能。
静态素材资源集
将 type 设置为
STATIC_LOCATION_GROUP。
您可以为任何类型的地址
同步素材资源集创建静态营业地点组素材资源集,无论您在
LocationSet中设置了哪些字段 (business_profile_location_set,
chain_location_set, 或 maps_location_set)。
对于 静态 营业地点组素材资源集,您需要 手动将生成的地址素材资源添加到营业地点组素材 资源集中。
将素材资源集附加到广告系列或广告组
使用
CampaignAssetSetService.MutateCampaignAssetSets
将 营业地点组素材资源集 附加到您的
广告系列。
或者,如果您想将营业地点组素材资源集附加到
广告组,请改用
AdGroupAssetSetService.MutateAdGroupAssetSets
。
(可选)将地址素材资源添加到静态 营业地点组素材资源集
仅当您之前创建了 静态营业地点组素材资源集时,才需要执行此步骤。
- 使用
asset_set_asset报告提取为 之前创建的地址同步素材资源集自动生成的素材资源的 资源名称。使用 过滤功能仅检索所需的素材资源 。 - 使用
AssetSetAssetService.MutateAssetSetAssets将它们添加到静态营业地点组素材资源集中。
管理商家资料营业地点 ID
当您使用 business_profile_location_set 并根据从商家资料网站或 API 检索到的
listing_id_filters
进行过滤时,可能需要
将这些数值从 uint64 类型转换为 int64 类型。如果您的代码在将商家资料地理位置 ID 添加到 listing_id_filters[] 重复字段时生成运行时错误,指出该 ID 超出范围,则您可能需要使用以下任一示例对其进行转换:
Java
/**
* Converts the business profile location ID to the format expected by the
* DynamicBusinessProfileLocationGroupFilter.listing_id_filters[] repeated field.
* The business profile location ID is an unsigned 64-bit integer, while the
* listing_id_filters[] field expects signed 64-bit integers. This means that
* for business profile location IDs that are out of range, we must perform the
* two's complement to convert it into a signed int.
*
* @param businessProfileLocationId The ID of a Business Profile location ID.
* @return a Business Profile location ID as a signed 64-bit integer (long).
*/
public static long convertBusinessProfileLocationId(String businessProfileLocationId) {
return Long.parseUnsignedLong(businessProfileLocationId);
}
C#
/// <summary>
/// Converts the business profile location ID to the format expected by the
/// DynamicBusinessProfileLocationGroupFilter.listing_id_filters[] repeated field.
/// The business profile location ID is an unsigned 64-bit integer, while the
/// listing_id_filters[] field expects signed 64-bit integers. This means that
/// for business profile location IDs that are out of range, we must perform the
/// two's complement to convert it into a signed int.
/// </summary>
/// <param name="businessProfileLocationId">The ID of a Business Profile location.</param>
/// <returns>The converted business location ID in signed 64 bit.</returns>
public long ConvertBusinessProfileLocationId(ulong businessProfileLocationId)
{
return unchecked((long)businessProfileLocationId);
}
PHP
/**
* Converts a business profile location ID to a signed 64 bit integer.
*
* Converts the business profile location ID to the format expected by the
* DynamicBusinessProfileLocationGroupFilter.listing_id_filters[] repeated field.
* The business profile location ID is an unsigned 64-bit integer, while the
* listing_id_filters[] field expects signed 64-bit integers. This means that
* for business profile location IDs that are out of range, we must perform the
* two's complement to convert it into a signed int.
*
* @param string $businessProfileLocationId the ID of a Business Profile location
* @return int the converted business location ID in signed 64 bit
*/
public static function convertBusinessProfileLocationId(string $businessProfileLocationId): int
{
$unsignedMax = '18446744073709551615'; // 2^64 - 1
$signedMax = '9223372036854775807'; // 2^63 - 1
// Check if the business profile location ID is within 64 bit range.
// If not, throw an error.
if (bccomp($businessProfileLocationId, '0') < 0 || bccomp($businessProfileLocationId, $unsignedMax) > 0) {
throw new InvalidArgumentException(
'The given business profile location id is outside of the range for a 64 bit integer.'
);
}
// Check if the business profile location ID is in signed 64 bit range.
// If it's not, convert it to its two's complement.
if (bccomp($businessProfileLocationId, $signedMax) > 0) {
// Two's complement: ID - 2^64
return (int) bcsub($businessProfileLocationId, '18446744073709551616');
}
return (int) $businessProfileLocationId;
}
Python
import ctypes
def convert_business_profile_location_id(business_profile_location_id):
"""Converts a business profile location ID to a signed 64 bit integer.
Converts the business profile location ID to the format expected by the
DynamicBusinessProfileLocationGroupFilter.listing_id_filters[] repeated field.
The business profile location ID is an unsigned 64-bit integer, while the
listing_id_filters[] field expects signed 64-bit integers. This means that
for business profile location IDs that are out of range, we must perform the
two's complement to convert it into a signed int.
Args:
business_profile_location_id: the ID of a Business Profile location ID.
Returns:
a Business Profile location ID as a signed 64 bit integer.
"""
# Check if the business profile location ID is within 64 bit range.
# If not, throw an error.
if business_profile_location_id >= 2 ** 64:
raise ValueError(
"The given business profile location id is outside of the range for a 64 bit integer."
)
# Check if the business profile location ID is in signed 64 bit range.
# If it's not, convert it to its two's complement.
elif business_profile_location_id >= 2 ** 63:
return ctypes.c_int64(business_profile_location_id).value
else:
return business_profile_location_id
Ruby
# Converts the business profile location ID to the format expected by the
# DynamicBusinessProfileLocationGroupFilter.listing_id_filters[] repeated field.
# The business profile location ID is an unsigned 64-bit integer, while the
# listing_id_filters[] field expects signed 64-bit integers. This means that
# for business profile location IDs that are out of range, we must perform the
# two's complement to convert it into a signed int.
# Since Ruby supports arbitrary precision numbers, we have to calculate it
# manually.
LONG_MAX = 2 ** 63
ULONG_MAX = LONG_MAX * 2
def convert_business_profile_location_id(business_profile_location_id)
# Check if the business profile location ID is within 64 bit range.
# If not, throw an error.
if business_profile_location_id >= 2 ** 64
raise "The given business profile location id is outside of the range for a 64 bit integer."
# Check if the business profile location ID is in signed 64 bit range.
# If it's not, convert it to its two's complement.
elseif business_profile_location_id >= 2**63
-1 * (ULONG_MAX - business_profile_location_id)
else
business_profile_location_id
end
end
Perl
use bigint;
# Converts the business profile location ID to the format expected by the
# DynamicBusinessProfileLocationGroupFilter.listing_id_filters[] repeated field.
# The business profile location ID is an unsigned 64-bit integer, while the
# listing_id_filters[] field expects signed 64-bit integers. This means that
# for business profile location IDs that are out of range, we must perform the
# two's complement to convert it into a signed int.
sub convert_business_profile_location_id {
my ($business_profile_location_id) = @_;
# Check if the business profile location ID is within 64 bit range.
# If not, throw an error.
if ($business_profile_location_id >= 2**64) {
die "The given business profile location id is outside of the range for a 64 bit integer";
# Check if the business profile location ID is in signed 64 bit range.
# If it's not, convert it to its two's complement.
} elseif ($business_profile_location_id >= 2**63) {
return -1 * (2**64 - $business_profile_location_id);
} else {
return $business_profile_location_id;
}
}