以下說明如何安裝及設定用戶端程式庫或 REST。
必要條件
安裝用戶端程式庫前,請先完成「設定 API 存取權」中的步驟,包括設定應用程式預設憑證 (ADC)。
安裝步驟
在本機電腦上安裝所選的用戶端程式庫:
REST
- 請使用帳戶和目的地的值,更新下列範例中的預留位置,例如 OPERATING_ACCOUNT_PRODUCT、OPERATING_ACCOUNT_ID 和 AUDIENCE_ID。
- 將 PROJECT_ID 替換為 Google Cloud 的 ID。
將範例複製到指令列,即可傳送要求。如果您是透過合作夥伴連結存取營運帳戶,請只使用「資料合作夥伴」範例。否則,請使用「廣告主」範例。
廣告主
#!/bin/bash # Uses gcloud to get an access token. If the Application Default # Credentials aren't for a service account then the command that # specifies --scopes fails, so this sample falls back to the command # without the --scopes argument. DATA_MANAGER_ACCESS_TOKEN="$(gcloud auth application-default print-access-token --scopes=https://www.googleapis.com/auth/datamanager || \ gcloud auth application-default print-access-token)" # Fetches and prints the scope information for the access token. If you # get scope-related errors when you send the request in the next step, # verify that this output includes the Data Manager API scope: # https://www.googleapis.com/auth/datamanager curl https://www.googleapis.com/oauth2/v1/tokeninfo?access_token="${DATA_MANAGER_ACCESS_TOKEN}" # Sends the request. curl -X POST "https://datamanager.googleapis.com/v1/audienceMembers:ingest" \ --header "Authorization: Bearer ${DATA_MANAGER_ACCESS_TOKEN}" \ --header "x-goog-user-project: PROJECT_ID" \ --header "Content-Type: application/json" \ --data @- <<EOF { "destinations": [ { "operatingAccount": { "accountType": "OPERATING_ACCOUNT_TYPE", "accountId": "OPERATING_ACCOUNT_ID" }, "loginAccount": { "accountType": "LOGIN_ACCOUNT_TYPE", "accountId": "LOGIN_ACCOUNT_ID" }, "productDestinationId": "AUDIENCE_ID" } ], "audienceMembers": [ { "compositeData": { "userData": { "userIdentifiers": [ { "emailAddress": "07e2f1394b0ea80e2adca010ea8318df697001a005ba7452720edda4b0ce57b3" }, { "emailAddress": "1df6b43bc68dd38eca94e6a65b4f466ae537b796c81a526918b40ac4a7b906c7" } ] } } }, { "compositeData": { "userData": { "userIdentifiers": [ { "emailAddress": "2ef46c4214c3fc1b277a2d976d55194e12b899aa50d721f28da858c7689756e3" }, { "emailAddress": "54e410b14fa652a4b49b43aff6eaf92ad680d4d1e5e62ed71b86cd3188385a51" }, { "emailAddress": "e8bd3f8da6f5af73bec1ab3fbf7beb47482c4766dfdfc94e6bd89e359c139478" } ] } } }, { "compositeData": { "userData": { "userIdentifiers": [ { "emailAddress": "05bb62526f091b45d20e243d194766cca8869137421047dc53fa4876d111a6f0" }, { "emailAddress": "f1fcde379f31f4d446b76ee8f34860eca2288adc6b6d6c0fdc56d9eee75a2fa5" } ] } } }, { "compositeData": { "userData": { "userIdentifiers": [ { "emailAddress": "83a834cc5327bc4dee7c5408988040dc5813c7662611cd93b707aff72bf7d33f" }, { "emailAddress": "223ebda6f6889b1494551ba902d9d381daf2f642bae055888e96343d53e9f9c4" } ] } } } ], "consent": { "adUserData": "CONSENT_GRANTED", "adPersonalization": "CONSENT_GRANTED" }, "encoding": "HEX", "termsOfService": { "customerMatchTermsOfServiceStatus": "ACCEPTED" }, "validateOnly": true } EOF資料合作夥伴
#!/bin/bash # Uses gcloud to get an access token. If the Application Default # Credentials aren't for a service account then the command that # specifies --scopes fails, so this sample falls back to the command # without the --scopes argument. DATA_MANAGER_ACCESS_TOKEN="$(gcloud auth application-default print-access-token --scopes=https://www.googleapis.com/auth/datamanager || \ gcloud auth application-default print-access-token)" # Fetches and prints the scope information for the access token. If # you get scope-related errors when you send the request in the next # step, verify that this output includes the Data Manager API scope: # https://www.googleapis.com/auth/datamanager curl https://www.googleapis.com/oauth2/v1/tokeninfo?access_token="${DATA_MANAGER_ACCESS_TOKEN}" # Sends the request. curl -X POST "https://datamanager.googleapis.com/v1/audienceMembers:ingest" \ --header "Authorization: Bearer ${DATA_MANAGER_ACCESS_TOKEN}" \ --header "x-goog-user-project: PROJECT_ID" \ --header "Content-Type: application/json" \ --data @- <<EOF { "destinations": [ { "operatingAccount": { "accountType": "OPERATING_ACCOUNT_TYPE", "accountId": "OPERATING_ACCOUNT_ID" }, "loginAccount": { "accountType": "LOGIN_ACCOUNT_TYPE", "accountId": "LOGIN_ACCOUNT_ID" }, "linkedAccount": { "accountType": "LINKED_ACCOUNT_TYPE", "accountId": "LINKED_ACCOUNT_ID" }, "productDestinationId": "AUDIENCE_ID" } ], "audienceMembers": [ { "compositeData": { "userData": { "userIdentifiers": [ { "emailAddress": "07e2f1394b0ea80e2adca010ea8318df697001a005ba7452720edda4b0ce57b3" }, { "emailAddress": "1df6b43bc68dd38eca94e6a65b4f466ae537b796c81a526918b40ac4a7b906c7" } ] } } }, { "compositeData": { "userData": { "userIdentifiers": [ { "emailAddress": "2ef46c4214c3fc1b277a2d976d55194e12b899aa50d721f28da858c7689756e3" }, { "emailAddress": "54e410b14fa652a4b49b43aff6eaf92ad680d4d1e5e62ed71b86cd3188385a51" }, { "emailAddress": "e8bd3f8da6f5af73bec1ab3fbf7beb47482c4766dfdfc94e6bd89e359c139478" } ] } } }, { "compositeData": { "userData": { "userIdentifiers": [ { "emailAddress": "05bb62526f091b45d20e243d194766cca8869137421047dc53fa4876d111a6f0" }, { "emailAddress": "f1fcde379f31f4d446b76ee8f34860eca2288adc6b6d6c0fdc56d9eee75a2fa5" } ] } } }, { "compositeData": { "userData": { "userIdentifiers": [ { "emailAddress": "83a834cc5327bc4dee7c5408988040dc5813c7662611cd93b707aff72bf7d33f" }, { "emailAddress": "223ebda6f6889b1494551ba902d9d381daf2f642bae055888e96343d53e9f9c4" } ] } } } ], "consent": { "adUserData": "CONSENT_GRANTED", "adPersonalization": "CONSENT_GRANTED" }, "encoding": "HEX", "termsOfService": { "customerMatchTermsOfServiceStatus": "ACCEPTED" }, "validateOnly": true } EOF
.NET
安裝用戶端程式庫
請按照 .NET 用戶端程式庫安裝指南中的操作說明,在專案中新增用戶端程式庫的依附元件。
選用:取得公用程式庫和程式碼範例。
複製 GitHub 存放區。
git clone https://github.com/googleads/data-manager-dotnet.git在 .NET 專案中,宣告公用程式庫的
ProjectReference依附元件。將 PATH_TO_UTILITY_LIBRARY 替換為您複製data-manager-dotnet存放區的位置。<ProjectReference Include="PATH_TO_UTILITY_LIBRARY\Google.Ads.DataManager.Util\src\Google.Ads.DataManager.Util.csproj" />如要格式化資料,請在 .NET 專案中使用
Formatter公用程式。瀏覽
samples子目錄中的程式碼範例,或前往 GitHub。切換至
samples目錄,並使用dotnet run取得可用範例清單。dotnet run執行範例時傳遞
--help引數,即可列印含有預期參數的使用情形陳述式。dotnet run -- ingest-audience-members --help如要開始使用一些範例資料,請使用
samples/sampledata中的檔案。
Go
安裝用戶端程式庫
go get cloud.google.com/go/datamanager/apiv1@latest
詳情請參閱 Go 用戶端程式庫指南。
Java
安裝用戶端程式庫
請按照 Java 用戶端程式庫安裝指南中的操作說明,在專案中加入用戶端程式庫的依附元件。
選用:安裝公用程式庫
除了用戶端程式庫,您也可以安裝公用程式庫,協助處理常見工作,例如格式化及加密要擷取的資料。
在 Java 專案中,宣告
data-manager-util公用程式庫的依附元件。Gradle:
implementation 'com.google.api-ads:data-manager-util:0.4.0'Maven:
<dependency> <groupId>com.google.api-ads</groupId> <artifactId>data-manager-util</artifactId> <version>0.4.0</version> </dependency>如要格式化及加密資料,請在 Java 專案中使用
UserDataFormatter和Encrypter公用程式。
瀏覽程式碼範例
瀏覽 data-manager-samples 子目錄中的程式碼範例,或前往 GitHub。
如要執行範例,請按照下列步驟操作:
複製 GitHub 存放區的
v0.4.0標記:git clone --branch v0.4.0 https://github.com/googleads/data-manager-java.git前往
data-manager-java目錄。使用 Gradle
run工作從指令列執行範例,並傳遞所有必要引數。執行範例時傳遞--help引數,即可列印用法陳述式和預期參數。舉例來說,下列指令會執行
IngestAudienceMembers範例並列印用法陳述式:./gradlew data-manager-samples:run \ --args='IngestAudienceMembers --help'
如要開始使用一些範例資料,請使用 data-manager-samples/src/main/resources/sampledata 中的檔案。
Node.js
安裝用戶端程式庫
請按照 Node.js 用戶端程式庫安裝指南中的操作說明,在專案中將依附元件新增至 @google-ads/datamanager 用戶端程式庫。
選用:安裝公用程式庫
除了用戶端程式庫,您也可以安裝公用程式庫,協助處理常見工作,例如格式化要擷取的資料。
在 Node.js 專案中,宣告
@google-ads/datamanager-util公用程式庫的依附元件:npm install @google-ads/datamanager-util如要格式化資料,請在 Node.js 專案中使用
UserDataFormatter公用程式。
瀏覽程式碼範例
瀏覽 samples 子目錄中的程式碼範例,或前往 GitHub。
如要執行範例,請按照下列步驟操作:
複製 GitHub 存放區的
v0.4.1標記:git clone --branch v0.4.1 https://github.com/googleads/data-manager-node.git前往
data-manager-node目錄。安裝執行範例所需的依附元件:
npm install執行範例,並傳遞任何必要引數。執行範例時傳遞
--help引數,即可列印用法陳述式和預期參數。舉例來說,下列指令會執行
ingest-audience-members範例,並列印用法陳述式:npm run ingest-audience-members -w samples -- --help
如要開始使用一些範例資料,請使用 samples/sampledata 中的檔案。
PHP
安裝用戶端程式庫
按照 PHP 用戶端程式庫安裝指南中的操作說明,在專案中將依附元件新增至 googleads/data-manager 用戶端程式庫。
選用:安裝公用程式庫
除了用戶端程式庫,您也可以安裝公用程式庫,協助處理常見工作,例如格式化要擷取的資料。
在同一主機上 PHP 專案的
composer.json檔案中,宣告公用程式庫的依附元件:composer require googleads/data-manager-util如要格式化資料,請在 PHP 專案中使用
Formatter公用程式。
瀏覽程式碼範例
瀏覽 samples 子目錄中的程式碼範例,或前往 GitHub。
如要執行範例,請按照下列步驟操作:
複製 GitHub 存放區的
v0.4.0標記:git clone --branch v0.4.0 https://github.com/googleads/data-manager-php.git前往
data-manager-php/samples目錄。安裝執行範例所需的依附元件:
composer install執行範例,並傳遞任何必要引數。執行範例時傳遞
--help引數,即可列印用法陳述式和預期參數。舉例來說,下列指令會執行
ingest_audience_members範例,並列印用法陳述式:php audiences/ingest_audience_members.php --help
如要開始使用一些範例資料,請使用 samples/sampledata 中的檔案。
Python
安裝用戶端程式庫
請按照 Python 用戶端程式庫安裝指南中的操作說明,在專案中將依附元件新增至 google-ads-datamanager 用戶端程式庫。
選用:安裝公用程式庫
除了用戶端程式庫,您也可以安裝公用程式庫,協助處理常見工作,例如格式化及加密要擷取的資料。
在 Python 專案中,宣告
google-ads-datamanager-util公用程式庫的依附元件。舉例來說,如果您在專案中使用
requirements.txt檔案,請在檔案中新增下列程式碼:google-ads-datamanager-util==0.4.0或直接安裝公用程式庫:
pip install google-ads-datamanager-util==0.4.0如要格式化及加密資料,請在 Python 專案中使用
Formatter和Encrypter公用程式。
瀏覽程式碼範例
複製 GitHub 存放區的
v0.4.0標記:git clone --branch v0.4.0 https://github.com/googleads/data-manager-python.git前往
data-manager-python目錄。安裝執行範例所需的依附元件:
pip install -r samples/requirements.txt執行範例,並傳遞任何必要引數。執行範例時傳遞
--help引數,即可列印用法陳述式和預期參數。舉例來說,下列指令會執行
ingest_audience_members範例並列印用法陳述式:python3 samples/audiences/ingest_audience_members.py --help
如要開始使用一些範例資料,請使用 samples/sampledata 中的檔案。
小茹
安裝用戶端程式庫
按照 Ruby 用戶端程式庫安裝指南中的操作說明,在專案中新增用戶端程式庫的依附元件。