data-manager-api-audience-ingestion
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseData Manager API Audience Ingestion
Data Manager API 受众成员上传
Core Directives
核心指令
- [IMPORTANT] When reading API documentation from developers.google.com, read
the Markdown equivalent of the page by appending to the URL.
.md.txt
- [重要提示] 阅读developers.google.com上的API文档时,请在URL后追加以查看对应的Markdown版本页面。
.md.txt
Sequential Implementation Workflow
分步实现流程
For simple informational, configuration, or setup questions, skip any irrelevant
steps and answer using only the relevant guidelines or documentation provided
below.
对于简单的信息查询、配置或设置类问题,请跳过无关步骤,仅使用以下相关指南或文档进行解答。
Step 1: Identify Use Case & Read Documentation
步骤1:确定使用场景并阅读文档
- Determine Destination Account Type: [CRITICAL] If it's not
explicitly stated, STOP and CLARIFY with the user where the data is being
sent (e.g., Google Ads, Display & Video 360, etc.) BEFORE generating any
code. Do NOT assume Google Ads by default. This maps to the field of the
account_typein theoperating_account.Destination - Read Documentation: [CRITICAL] You MUST follow the relevant audience
upload overview for implementation steps:
- Google Ads Customer Match: Upload members to an audience
- DV360 Customer Match: Upload members to an audience
Step 2: Setup Auth
步骤2:设置认证
- Enable API (Prerequisite): Check that the user has enabled the Data Manager API in their Google Cloud project.
- Generate ADC: Authenticate the local workspace using Application
Default Credentials (ADC) via .
gcloud auth application-default login- Required Scopes: Include scopes
and
https://www.googleapis.com/auth/datamanager.https://www.googleapis.com/auth/cloud-platform - Multi-API Scopes: If using the same credentials for other APIs,
append their scopes (e.g.,
).
https://www.googleapis.com/auth/adwords - Service Accounts: Ensure the Service Account has the
IAM role, and the user executing
Service Usage Consumerhas the Token Creator role (gcloud) on that Service Account for impersonation.roles/iam.serviceAccountTokenCreator
- Required Scopes: Include scopes
- Reference: Refer to Set up API access
for a walkthrough of the CLI auth setup.
gcloud
- 启用API(前提条件):检查用户是否已在其Google Cloud项目中启用Data Manager API。
- 生成ADC:通过命令使用应用默认凭据(ADC)对本地工作区进行认证。
gcloud auth application-default login- 所需权限范围:需包含和
https://www.googleapis.com/auth/datamanager权限范围。https://www.googleapis.com/auth/cloud-platform - 多API权限范围:如果使用相同凭据访问其他API,请追加对应权限范围(例如)。
https://www.googleapis.com/auth/adwords - 服务账号:确保服务账号拥有IAM角色,且执行
Service Usage Consumer命令的用户在该服务账号上拥有gcloud角色(Token Creator)以进行身份模拟。roles/iam.serviceAccountTokenCreator
- 所需权限范围:需包含
- 参考文档:请参阅设置API访问权限以获取CLI认证设置的分步指南。
gcloud
Step 3: Install Client Library and Utilities
步骤3:安装客户端库及工具库
Refer to Install a client
library
for detailed installation instructions.
| Language | Installation Instructions |
|---|---|
| Python | |
| Java | Follow the quickstart instructions to install the Maven/Gradle dependency. |
| Node | |
| PHP | Install the |
| .NET | Install the |
[IMPORTANT] The utility library is NOT available on public package managers
(such as PyPI or Maven). Follow the below instructions to install:
- Clone the repository from GitHub using the commands from the table below.
- Always use the latest available version of the library. Determine the
actual version identifier () from the cloned repository metadata.
VERSION- Python: Find the version in
pyproject.toml - Java: Find the version in (as the
util/package.jsonfield).version - Node: Find the version in (as the
composer.jsonfield).version
- Python: Find the version in
- Follow the language-specific instructions in the next section to build
and install the utility dependency, replacing with the version identifier you found.
VERSION
| Language | Git Clone Command |
|---|---|
| Python | |
| Java | |
| Node | |
| PHP | |
| .NET | |
请参阅安装客户端库获取详细安装说明。
| 语言 | 安装说明 |
|---|---|
| Python | |
| Java | 按照快速入门说明安装Maven/Gradle依赖。 |
| Node | |
| PHP | 使用Composer安装 |
| .NET | 安装 |
[重要提示] 工具库无法从公共包管理器(如PyPI或Maven)获取,请按照以下说明安装:
- 使用下表中的命令从GitHub克隆代码仓库。
- 始终使用库的最新版本。从克隆仓库的元数据中确定实际版本标识符():
VERSION- Python:在中查找版本号
pyproject.toml - Java:在的
util/package.json字段中查找版本号version - Node:在的
composer.json字段中查找版本号version
- Python:在
- 按照下一节中的语言特定说明构建并安装工具库依赖,将替换为你找到的版本标识符。
VERSION
| 语言 | Git克隆命令 |
|---|---|
| Python | |
| Java | |
| Node | |
| PHP | |
| .NET | |
Install Utility Library
安装工具库
Python
Python
- Navigate to the directory and install the utility library:
data-manager-pythonshellpip install . - Declare a dependency in your project's file (replacing
requirements.txtwith the identified version):VERSIONundefined
google-ads-datamanager-util=VERSION
```
- 进入目录并安装工具库:
data-manager-pythonshellpip install . - 在项目的文件中声明依赖(将
requirements.txt替换为已确定的版本号):VERSIONundefined
google-ads-datamanager-util=VERSION
```
Java
Java
- Navigate to the directory.
data-manager-java - Build and publish the utility library to your local Maven repository:
shell
./gradlew data-manager-util:install-
Declare a dependency on the utility library in your project (replacingwith the identified latest version):
VERSION- Gradle:
noneimplementation 'com.google.api-ads:data-manager-util:VERSION'- Maven:
xml<dependency> <groupId>com.google.api-ads</groupId> <artifactId>data-manager-util</artifactId> <version>VERSION</version> </dependency>
- 进入目录。
data-manager-java - 构建工具库并发布到本地Maven仓库:
shell
./gradlew data-manager-util:install-
在项目中声明工具库依赖(将替换为已确定的最新版本号):
VERSION- Gradle:
noneimplementation 'com.google.api-ads:data-manager-util:VERSION'- Maven:
xml<dependency> <groupId>com.google.api-ads</groupId> <artifactId>data-manager-util</artifactId> <version>VERSION</version> </dependency>
Node
Node
- Navigate to the directory and install dependencies:
data-manager-node
shell
npm install- Navigate to the directory:
util
shell
cd util- Pack the utility library into a archive:
.tgz
shell
npm pack- Declare a dependency in your Node.js project's pointing to the path of the generated
package.jsonarchive (replacing.tgzwith the identified version):VERSION
json
{
"dependencies": {
"@google-ads/data-manager-util": "file:/path/to/google-ads-datamanager-util-VERSION.tgz"
}
}- 进入目录并安装依赖:
data-manager-node
shell
npm install- 进入目录:
util
shell
cd util- 将工具库打包为归档文件:
.tgz
shell
npm pack- 在Node.js项目的中声明依赖,指向生成的
package.json归档文件路径(将.tgz替换为已确定的版本号):VERSION
json
{
"dependencies": {
"@google-ads/data-manager-util": "file:/path/to/google-ads-datamanager-util-VERSION.tgz"
}
}PHP
PHP
- Navigate to the directory.
data-manager-php - Resolve dependencies for the library:
shell
composer update --prefer-dist- Update your project's to declare a dependency on the utility library using a path repository:
composer.json
json
{
"repositories": [
{
"type": "path",
"url": "/path/to/cloned/data-manager-php"
}
],
"require": {
"googleads/data-manager-util": "@dev"
}
}- 进入目录。
data-manager-php - 解析库的依赖:
shell
composer update --prefer-dist- 更新项目的,使用路径仓库声明工具库依赖:
composer.json
json
{
"repositories": [
{
"type": "path",
"url": "/path/to/cloned/data-manager-php"
}
],
"require": {
"googleads/data-manager-util": "@dev"
}
}.NET
.NET
In your .NET project, declare a dependency pointing to the
cloned library's path:
ProjectReference.csprojxml
<ProjectReference Include="\path\to\cloned\Google.Ads.DataManager.Util\src\Google.Ads.DataManager.Util.csproj" />在你的.NET项目中,声明依赖,指向克隆库的路径:
ProjectReference.csprojxml
<ProjectReference Include="\path\to\cloned\Google.Ads.DataManager.Util\src\Google.Ads.DataManager.Util.csproj" />Step 4: Retrieve Code Sample
步骤4:获取代码示例
[IMPORTANT] If writing or updating an ingestion script, ALWAYS retrieve the
relevant code sample to use as a reference:
| Language | Sample |
|---|---|
| Python | |
| Java | |
| PHP | |
| Node | |
| .NET | |
[重要提示] 如果编写或更新上传脚本,请务必获取相关代码示例作为参考:
Step 5: Retrieve migration guides
步骤5:获取迁移指南
[CRITICAL] If refactoring code to upgrade from another Google API, ALWAYS
extract the full contents of the relevant field mapping guide.
[关键] 如果重构代码以从其他谷歌API升级,请务必提取相关字段映射指南的完整内容。
Google Ads
Google Ads
- Google Ads API Customer Match: Google Ads API to Customer Match Migration Field Mappings
- Google Ads API Customer Match: Google Ads API 到 Customer Match 迁移字段映射
Display & Video 360
Display & Video 360
- Display & Video 360 API Customer Match: Display & Video 360 API to Customer Match Migration Field Mappings
- Display & Video 360 API Customer Match: Display & Video 360 API 到 Customer Match 迁移字段映射
Step 6: Implementation
步骤6:实现
Implement the ingestion logic using the following checkpoints:
- Initialize Client: Instantiate the Data Manager client
().
IngestionServiceClient - Define Destinations: Build the object using the
Destinationand the appropriate account configurations:product_destination_id(target account receiving data),operating_account(if authenticating using a manager account or a data partner account), andlogin_account(if you're a data partner accessing the account via a partner link to a manager account). STRONGLY RECOMMENDED: Refer to the Configure destinations and headers guide for more details on configuring destinations.linked_account - Format User Data: Use the utility library helpers to normalize and hash user identifiers correctly.
- Construct Payload: Build the request payload
() containing the destinations, formatted members, and consent permissions.
IngestAudienceMembersRequest - Send Request: Execute and record the returned request ID for logging/troubleshooting.
ingest_audience_members
使用以下检查点实现上传逻辑:
- 初始化客户端:实例化Data Manager客户端()。
IngestionServiceClient - 定义目标:使用和适当的账户配置构建
product_destination_id对象:Destination(接收数据的目标账户)、operating_account(如果使用管理账户或数据合作伙伴账户进行认证),以及login_account(如果是数据合作伙伴通过合作伙伴链接访问管理账户下的账户)。强烈建议:参阅配置目标和请求头指南获取更多关于配置目标的详细信息。linked_account - 格式化用户数据:使用工具库的辅助函数正确标准化并哈希用户标识符。
- 构建请求负载:构建包含目标、格式化后的成员数据和同意权限的请求负载()。
IngestAudienceMembersRequest - 发送请求:执行并记录返回的请求ID用于日志记录和故障排查。
ingest_audience_members
Formatting
格式化
-
Fetch the Format user data guide and use that as the source of truth for formatting and normalization rules.
-
Use the utility library to format, hash, and encrypt user data (emails, phone numbers, addresses).Python Example:python
from google.ads.datamanager_util import Formatter from google.ads.datamanager_util.format import Encoding formatter: Formatter = Formatter() processed_email: str = formatter.process_email_address( email, Encoding.HEX )
-
获取格式化用户数据指南,并以此作为格式化和标准化规则的权威来源。
-
使用工具库格式化、哈希和加密用户数据(电子邮件、电话号码、地址)。Python示例:python
from google.ads.datamanager_util import Formatter from google.ads.datamanager_util.format import Encoding formatter: Formatter = Formatter() processed_email: str = formatter.process_email_address( email, Encoding.HEX )
Critical Gotchas
关键注意事项
- Do NOT set the field on
addressunless all required fields are present (UserIdentifier,postal_code,family_name,given_name); incomplete address fields will cause the API request to fail.region_code - must be a numeric string. It is NOT a resource name.
product_destination_id - The enum values for are
ConsentStatusandCONSENT_GRANTED. Do not use the valuesCONSENT_DENIEDandGRANTED.DENIED - Field names on are
UserIdentifierandemail_address. Do not use the Google Ads API field namesphone_numberandhashed_email.hashed_phone_number
- 除非所有必填字段(、
postal_code、family_name、given_name)都存在,否则请勿设置region_code上的UserIdentifier字段;不完整的地址字段会导致API请求失败。address - 必须是数字字符串,而非资源名称。
product_destination_id - 的枚举值为
ConsentStatus和CONSENT_GRANTED,请勿使用CONSENT_DENIED和GRANTED。DENIED - 上的字段名称为
UserIdentifier和email_address,请勿使用Google Ads API的字段名称phone_number和hashed_email。hashed_phone_number
Error Handling & Troubleshooting
错误处理与故障排查
Inspecting Error Payloads
检查错误负载
[IMPORTANT] Refer to
Understand API Errors
for a detailed guide on how to understand the structure of errors returned by
the API.
[重要提示] 请参阅理解API错误指南,详细了解API返回错误的结构。
API Reference
API参考
When implementing or debugging API integrations, use the API reference to lookup
field names, types, and acceptable values. DO NOT guess values.
- Send audience members guide: https://developers.google.com/data-manager/api/devguides/audiences/send-audience-members
- REST API Reference: https://developers.google.com/data-manager/api/reference/rest/v1/audienceMembers/ingest
在实现或调试API集成时,请使用API参考查找字段名称、类型和可接受的值。请勿猜测值。