W przeciwieństwie do innych komponentów komponenty z lokalizacją są tworzone automatycznie przez interfejs Google Ads API po utworzeniu przez Ciebie grupy plików. Najpierw utwórz zestaw komponentów synchronizacji lokalizacji i dołącz go do klienta. Jeśli w przypadku kampanii lub grupy reklam musisz wybrać podzbiór komponentów z lokalizacją w zbiorze komponentów, utwórz zbiór komponentów z grupą lokalizacji i dołącz go do kampanii lub grupy reklam.
Utwórz zestaw komponentów synchronizacji lokalizacji i dołącz go do klienta.
- Utwórz zestaw komponentów synchronizacji lokalizacji.
- Przypisz go do klienta za pomocą
CustomerAssetSetService.
Tworzenie zestawu komponentów synchronizacji lokalizacji
- Utwórz nowy
AssetSet.- Ustaw
typenaLOCATION_SYNC. - Ustaw
location_setna nowyLocationSet.
- Ustaw
W nowym
LocationSet- Ustaw wartość parametru
location_ownership_typena podstawie przypadku użycia:- Ustaw wartość
BUSINESS_OWNER, jeśli jesteś właścicielem adresu sklepu. - Ustaw wartość
AFFILIATE, jeśli nie jesteś właścicielem adresu sklepu, ale sprzedajesz w nim swoje produkty.
- Ustaw wartość
Ustaw pole
sourceoneof na podstawie przypadku użycia:Ustaw
business_profile_location_set, jeśli chcesz synchronizować lokalizacje z kontem Profilu Firmy w Google.Gdy tworzysz
BusinessProfileLocationSet, aby połączyć Google Ads z kontem Profilu Firmy w Google, musisz podać token dostępu OAuth 2.0 w poluhttp_authorization_token. Ten token jest dowodem na to, że zezwalasz Google Ads na dostęp do danych o lokalizacji z określonego profilu firmy w Google.Token musi spełniać te wymagania:
- Musi być wygenerowany dla konta Google (użytkownika lub usługi), którego adres e-mail jest podany w
email_addresswBusinessProfileLocationSet. - To konto musi mieć wystarczające uprawnienia do odczytywania lokalizacji firm w Profilu Firmy w Google.
- Token OAuth 2.0 musi zostać uzyskany w zakresie
https://www.googleapis.com/auth/business.manage.
Szczegółowe instrukcje generowania tokena dostępu OAuth 2.0 znajdziesz w artykule Używanie protokołu OAuth 2.0 na potrzeby dostępu do interfejsów API Google.
- Musi być wygenerowany dla konta Google (użytkownika lub usługi), którego adres e-mail jest podany w
Ustaw
chain_location_set, jeśli chcesz synchronizować dane z lokalizacjami w określonych identyfikatorach sieci.Ustaw
maps_location_set, jeśli chcesz ręcznie dodawać lokalizacje za pomocą identyfikatorów miejsc.
- Ustaw wartość parametru
Po wykonaniu tych czynności interfejs Google Ads API wygeneruje komponenty lokalizacji i doda je do utworzonego zestawu komponentów synchronizacji lokalizacji, podobnie jak w przypadku ręcznego dodawania komponentów za pomocą AssetSetAssetService. Nie musisz ich modyfikować, chyba że chcesz ręcznie dodać je do statycznego zestawu komponentów grupy lokalizacji.
Klient może mieć tylko 1 aktywny zestaw komponentów do synchronizacji lokalizacji z ustawieniem status na ENABLED. Jeśli chcesz utworzyć komponent z lokalizacją innego typu, najpierw usuń dotychczasowy.
Dołączanie zestawu komponentów synchronizacji lokalizacji do klienta
Użyj
CustomerAssetSetService.MutateCustomerAssetSets
, aby dołączyć do klienta zestaw komponentów synchronizacji lokalizacji skonfigurowany w poprzedniej sekcji.
(Opcjonalnie) Utwórz zestaw komponentów z grupą lokalizacji i dołącz go do kampanii lub grupy reklam.
Zestaw komponentów grupy lokalizacji jest potrzebny tylko wtedy, gdy chcesz wybrać podzbiór komponentów z lokalizacją. Wynika to z faktu, że kampanie i grupy reklam dziedziczą komponenty z lokalizacją z poziomu klienta.
Zestawy komponentów z grupą lokalizacji zawierają podzbiór komponentów z lokalizacją z zestawu komponentów synchronizacja lokalizacji. Możesz dynamicznie tworzyć zestaw komponentów grupy lokalizacji, korzystając z niektórych funkcji Profilu Firmy w Google (np. filtrowania według etykiet) lub identyfikatorów i lokalizacji sieci. Możesz też statycznie utworzyć zestaw komponentów grupy lokalizacji.
- Utwórz zestaw komponentów grupy lokalizacji. Zestaw komponentów z grupą lokalizacji może być dynamiczny lub statyczny.
- Dołącz zestaw komponentów do kampanii lub grupy reklam, w zależności od potrzeb.
- (Opcjonalnie) Dodaj wcześniej wygenerowane komponenty do nowo utworzonego statycznego zestawu komponentów grupy lokalizacji.
Dla danego klienta możesz utworzyć wiele dynamicznych lub statycznych zestawów komponentów grupy lokalizacji.
Tworzenie zestawu komponentów grupy lokalizacji
Utwórz nowy obiekt AssetSet i ustaw
location_group_parent_asset_set_id na identyfikator wcześniej utworzonego zestawu komponentów z synchronizacją lokalizacji.
Następnie ustaw niektóre pola w zależności od tego, czy chcesz utworzyć dynamiczny czy statyczny zestaw komponentów grupy lokalizacji.
Dynamiczne zestawy komponentów
W zależności od pola ustawionego w LocationSet skonfiguruj pola zgodnie z tą regułą:
| Jeśli ustawisz to pole: | Następnie ustaw type na | i ustaw to pole jako pole 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 |
Jeśli podczas maps_location_set tworzenia zestawu komponentów synchronizacji lokalizacji ustawisz wartość, nie będziesz mieć możliwości utworzenia zestawu komponentów dynamicznej grupy lokalizacji. Dzieje się tak, ponieważ lokalizacje zostały dodane ręcznie za pomocą identyfikatorów miejsc i nie ma funkcji filtrowania, których można by użyć w przypadku tego typu lokalizacji.
Statyczne zestawy komponentów
Ustaw type na STATIC_LOCATION_GROUP.
Możesz tworzyć statyczne zestawy plików do grup lokalizacji dla dowolnych typów zestawów plików do synchronizacji lokalizacji, niezależnie od tego, jakie pola (business_profile_location_set, chain_location_set lub maps_location_set) ustawisz w LocationSet.
W przypadku statycznych zestawów komponentów z lokalizacją musisz ręcznie dodać wygenerowane komponenty z lokalizacją do zestawów komponentów z lokalizacją w grupie lokalizacji.
Dołączanie zestawu komponentów do kampanii lub grupy reklam
Użyj
CampaignAssetSetService.MutateCampaignAssetSets
aby dołączyć do kampanii zestaw komponentów grupy lokalizacji.
Zamiast tego użyj
AdGroupAssetSetService.MutateAdGroupAssetSets
jeśli chcesz dołączyć zestaw komponentów grupy lokalizacji do
grupy reklam.
(Opcjonalnie) Dodaj komponenty z lokalizacją do zestawu komponentów grupy lokalizacji statycznej.
Ten krok jest wymagany tylko wtedy, gdy wcześniej utworzysz statyczny zestaw komponentów grupy lokalizacji.
- Użyj raportu
asset_set_asset, aby pobrać nazwy zasobów komponentów wygenerowanych automatycznie na potrzeby utworzonego wcześniej zestawu komponentów do synchronizacji lokalizacji. Użyj filtrowania, aby pobrać tylko te zasoby, które Cię interesują. - Dodaj je do zestawu komponentów statycznej grupy lokalizacji za pomocą
AssetSetAssetService.MutateAssetSetAssets.
Zarządzanie identyfikatorami lokalizacji w profilu firmy
Jeśli używasz znaku business_profile_location_set i filtrujesz dane listing_id_filters pobrane z witryny Profilu Firmy lub interfejsu API, może być konieczne przekonwertowanie tych wartości liczbowych z typu uint64 na int64. Jeśli Twój kod generuje błąd czasu wykonania, który informuje, że identyfikator lokalizacji profilu firmy jest poza zakresem podczas dodawania go do listing_id_filters[] pola powtarzanego, prawdopodobnie musisz go przekonwertować, korzystając z jednego z tych przykładów:
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;
}
}