ชิ้นงานสถานที่ตั้งแตกต่างจากชิ้นงานอื่นๆ ตรงที่ Google Ads API จะสร้างชิ้นงานสถานที่ตั้งโดยอัตโนมัติหลังจากที่คุณสร้างชุดชิ้นงาน ก่อนอื่น ให้สร้างชุดชิ้นงานการซิงค์สถานที่ตั้งและแนบกับลูกค้า จากนั้น หากต้องการเลือกชุดย่อยของชิ้นงานสถานที่ตั้งในชุดชิ้นงานสําหรับแคมเปญหรือกลุ่มโฆษณา ให้สร้างชุดชิ้นงานกลุ่มสถานที่ตั้งและแนบกับแคมเปญหรือกลุ่มโฆษณา
สร้างชุดชิ้นงานการซิงค์สถานที่ตั้งและแนบกับลูกค้า
สร้างชุดชิ้นงานการซิงค์สถานที่ตั้ง
- สร้าง
AssetSetใหม่- ตั้งค่า
typeเป็นLOCATION_SYNC - ตั้งค่า
location_setเป็นLocationSetใหม่
- ตั้งค่า
ใน
LocationSetใหม่- ตั้งค่า
location_ownership_typeตามกรณีการใช้งานของคุณ ดังนี้- ตั้งค่าเป็น
BUSINESS_OWNERหากคุณเป็นเจ้าของที่ตั้งธุรกิจ - ตั้งค่าเป็น
AFFILIATEหากคุณไม่ได้เป็นเจ้าของสถานที่ตั้งของธุรกิจ แต่ขายผลิตภัณฑ์ที่นั่น
- ตั้งค่าเป็น
ตั้งค่าช่อง
sourceoneof ตามกรณีการใช้งานของคุณ ดังนี้ตั้งค่า
business_profile_location_setหากต้องการซิงค์กับสถานที่ตั้งในบัญชี Google Business Profileเมื่อสร้าง
BusinessProfileLocationSetเพื่อลิงก์ Google Ads กับบัญชี Google Business Profile คุณต้องระบุโทเค็นเพื่อการเข้าถึง OAuth 2.0 ในช่องhttp_authorization_tokenโทเค็นนี้ทำหน้าที่เป็นหลักฐานว่าคุณอนุญาตให้ Google Ads เข้าถึงข้อมูลตำแหน่งจาก Google Business Profile ที่ระบุโทเค็นต้องเป็นไปตามข้อกำหนดต่อไปนี้
- โดยต้องสร้างขึ้นสำหรับบัญชี Google (บัญชีผู้ใช้หรือบัญชีบริการ) ที่ระบุอีเมลไว้ในช่อง
email_addressของBusinessProfileLocationSet - บัญชีนี้ต้องมีสิทธิ์เพียงพอในการอ่านสถานที่ตั้งธุรกิจภายใน Google Business Profile
- ต้องได้���ับโทเค็น OAuth 2.0 ที่มีขอบเขต
https://www.googleapis.com/auth/business.manage
ดูวิธีการสร้างโทเค็นเพื่อการเข้าถึง OAuth 2.0 โดยละเอียดได้ที่การใช้ OAuth 2.0 เพื่อเข้าถึง Google APIs
- โดยต้องสร้างขึ้นสำหรับบัญชี Google (บัญชีผู้ใช้หรือบัญชีบริการ) ที่ระบุอีเมลไว้ในช่อง
ตั้งค่า
chain_location_setหากต้องการซิงค์กับสถานที่ตั้งในรหัสเครือธุรกิจที่ระบุตั้งค่า
maps_location_setหากต้องการเพิ่มสถานที่ตั้งด้วยตนเองโดยใช้รหัสสถานที่
- ตั้งค่า
หลังจากทำตามขั้นตอนเหล่านี้เสร็จแล้ว Google Ads API จะสร้างชิ้นงานสถานที่ตั้งและเพิ่มลงในชุดชิ้นงานการซิงค์สถานที่ตั้งที่สร้างขึ้นให้คุณ ซึ่งคล้ายกับเมื่อคุณดำเนินการด้วยตนเองโดยใช้ AssetSetAssetService คุณไม่จำเป็นต้องจัดการชิ้นงานเหล่านี้ เว้นแต่จะต้องการเพิ่มชิ้นงานลงในชุดชิ้นงานกลุ่มสถานที่ตั้งแบบคงที่ด้วยตนเอง
ลูกค้ามีชุดชิ้นงานการซิงค์สถานที่ตั้งที่ใช้งานอยู่ได้เพียงชุดเดียว โดยตั้งค่า status เป็น ENABLED หากต้องการสร้างชุดชิ้นงานการซิงค์สถานที่ตั้งประเภทอื่น ให้นําชุดชิ้นงานที่มีอยู่ออกก่อน
แนบชุดชิ้นงานการซิงค์สถานที่ตั้งกับลูกค้า
ใช้
CustomerAssetSetService.MutateCustomerAssetSets
เพื่อแนบชุดชิ้นงานการซิงค์สถานที่ตั้งที่ตั้งค่าไว้ในส่วนก่อนหน้ากับลูกค้า
(ไม่บังคับ) สร้างชุดชิ้นงานกลุ่มสถานที่ตั้งและแนบกับแคมเปญหรือกลุ่มโฆษณา
ชุดชิ้นงานกลุ่มสถานที่ตั้งจำเป็นเฉพาะในกรณีที่คุณต้องเลือกชุดย่อยของชิ้นงานสถานที่ตั้งเท่านั้น เนื่องจากแคมเปญและกลุ่มโฆษณาจะรับค่าชิ้นงานสถานที่ตั้งจากระดับลูกค้า
ชุดชิ้นงานกลุ่มสถานที่ตั้งมีชุดย่อยของชิ้นงานสถานที่ตั้งของชุดชิ้นงานการซิงค์สถานที่ตั้ง คุณสามารถสร้างชุดชิ้นงานกลุ่มสถานที่ตั้งแบบไดนามิกได้โดยใช้ประโยชน์จากฟีเจอร์บางอย่างของ Google Business Profile (เช่น การกรองตามป้ายกำกับ) หรือรหัสเครือร้านค้าและสถานที่ตั้งของเครือร้านค้า หรือจะสร้างชุดชิ้นงานกลุ่มสถานที่ตั้งแบบคงที่ก็ได้
- สร้างชุดชิ้นงานกลุ่มสถานที่ตั้ง ชุดชิ้นงานกลุ่มสถานที่ตั้งอาจเป็นแบบไดนามิกหรือคงที่ก็ได้
- แนบชุดชิ้นงานกับแคมเปญหรือกลุ่มโฆษณาตามความต้องการ
- (ไม่บังคับ) เพิ่มชิ้นงานที่สร้างไว้ก่อนหน้านี้ลงในชุดชิ้นงานกลุ่มสถานที่ตั้งแบบคงที่ที่สร้างขึ้นใหม่
คุณสามารถสร้างชุดชิ้นงานกลุ่มสถานที่ตั้งแบบไดนามิกหรือแบบคงที่ได้หลายชุดสําหรับลูกค้าหนึ่งๆ
สร้างชุดชิ้นงานกลุ่มสถานที่ตั้ง
สร้าง AssetSet ใหม่และตั้งค่า location_group_parent_asset_set_id เป็นรหัสของชุดชิ้นงานการซิงค์สถานที่ตั้งที่สร้างไว้ก่อนหน้านี้
จากนั้นตั้งค่าบางฟิลด์โดยพิจารณาว่าคุณต้องการสร้างชุดชิ้นงานกลุ่มสถานที่ตั้งแบบไดนามิกหรือแบบคงที่
ชุดชิ้นงานแบบไดนามิก
ตั้งค่าฟิลด์ตามกฎต่อไปนี้ ทั้งนี้ขึ้นอยู่กับฟิลด์ที่คุณตั้งค่าใน LocationSet
| หากคุณตั้งค่าช่องต่อไปนี้ | จากนั้นตั้งค่า type เป็น | และตั้งค่าช่องนี้เป็นช่อง 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 เมื่อสร้างชุดชิ้นงานการซิงค์สถานที่ตั้ง คุณจะสร้างชุดชิ้นงานกลุ่มสถานที่ตั้งแบบไดนามิกไม่ได้ เนื่องจากคุณได้เพิ่มสถานที่ตั้งด้วยตนเองโดยใช้รหัสสถานที่ และไม่มีฟีเจอร์การกรองที่คุณใช้กับสถานที่ตั้งประเภทนี้ได้
ชุดชิ้นงานแบบคงที่
ตั้งค่า type เป็น STATIC_LOCATION_GROUP
คุณสามารถสร้างชุดชิ้นงานกลุ่มสถานที่ตั้งแบบคงที่สําหรับชุดชิ้นงานการซิงค์สถานที่ตั้งประเภทใดก็ได้ ไม่ว่าคุณจะตั้งค่าช่องใด (business_profile_location_set, chain_location_set หรือ maps_location_set) ใน LocationSet
สําหรับชุดชิ้นงานกลุ่มสถานที่ตั้งแบบคงที่ คุณต้องเพิ่มชิ้นงานสถานที่ตั้งที่สร้างขึ้นลงในชุดชิ้นงานกลุ่มสถานที่ตั้งด้วยตนเอง
แนบชุดชิ้นงานกับแคมเปญหรือกลุ่มโฆษณา
ใช้
CampaignAssetSetService.MutateCampaignAssetSets
เพื่อแนบชุดชิ้นงานกลุ่มสถานที่ตั้งกับแคมเปญ
หรือใช้ AdGroupAssetSetService.MutateAdGroupAssetSets หากต้องการแนบชุดชิ้นงานกลุ่มสถานที่ตั้งกับกลุ่มโฆษณาแทน
(ไม่บังคับ) เพิ่มชิ้นงานสถานที่ตั้งลงในชุดชิ้นงานกลุ่มสถานที่ตั้งแบบคงที่
ขั้นตอนนี้จำเป็นเฉพาะในกรณีที่คุณสร้างชุดชิ้นงานกลุ่มสถานที่ตั้งแบบคงที่ไว้ก่อนหน้านี้
- ใช้รายงาน
asset_set_assetเพื่อดึงชื่อทรัพยากรของชิ้นงานที่สร้างขึ้นโดยอัตโนมัติสําหรับชุดชิ้นงานการซิงค์สถานที่ตั้งที่สร้างไว้ก่อนหน้านี้ ใช้การกรองเพื่อดึงเฉพาะชิ้นงานที่ต้องการ - เพิ่มสถานที่ตั้งลงในชุดชิ้นงานกลุ่มสถานที่ตั้งแบบคงที่โดยใช้
AssetSetAssetService.MutateAssetSetAssets
จัดการรหัสสถานที่ตั้งของ Business Profile
เมื่อคุณใช้ business_profile_location_set และกรอง listing_id_filters ที่ดึงมาจากเว็บไซต์หรือ API ของ Business Profile คุณอาจต้องแปลงค่าตัวเลขเหล่านี้จากประเภท uint64 เป็น int64 หากโค้ดสร้างข้อผิดพลาดขณะรันไทม์ว่ารหัสสถานที่ตั้งของ Business Profile อยู่นอกช่วงเมื่อเพิ่มลงในฟิลด์ที่ซ้ำได้ listing_id_filters[] คุณอาจต้องแปลงรหัสดังกล่าวโดยใช้ตัวอย่างต่อไปนี้
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 < 0 or 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 < 0 || 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.
elsif 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 < 0 || $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.
} elsif ($business_profile_location_id >= 2**63) {
return -1 * (2**64 - $business_profile_location_id);
} else {
return $business_profile_location_id;
}
}