ใช้ Google Ad Manager API (เบต้า) เพื่ออ่านข้อมูล Ad Manager และเรียกใช้รายงาน
หากต้องการส่งคําขอ API รายการแรก ให้ทําตามขั้นตอนต่อไปนี้
รับสิทธิ์เข้าถึงเครือข่าย Ad Manager
หากยังไม่มี โปรดลงชื่อสมัครใช้บัญชี Ad Manager
เปิดใช้ Ad Manager API
เปิดใช้ Ad Manager API ในโปรเจ็กต์คอนโซล Google API
ตรวจสอบสิทธิ์
คำขอ API ทั้งหมดต้องได้รับการตรวจสอบสิทธิ์โดยใช้ OAuth2
ไลบรารีของไคลเอ็นต์ Ad Manager API จะอ่านข้อมูลเข้าสู่ระบบจากข้อมูลเข้าสู่ระบบเริ่มต้นของแอปพลิเคชัน คุณสามารถตั้งค่าเหล่านี้ได้โดยใช้ตัวแปรสภาพแวดล้อมหรือ gcloud
Linux หรือ macOS
export GOOGLE_APPLICATION_CREDENTIALS=KEY_FILE_PATH
Windows
set GOOGLE_APPLICATION_CREDENTIALS=KEY_FILE_PATH
gcloud auth application-default login --scopes="https://www.googleapis.com/auth/admanager"
# End user credentials must specify the cloud project where the API is enabled.
gcloud auth application-default set-quota-project PROJECT_ID
ดูข้อมูลเพิ่มเติมเกี่ยวกับการเลือกประเภทข้อมูลเข้าสู่ระบบและการสร้างข้อมูลเข้าสู่ระบบได้ที่คู่มือการตรวจสอบสิทธิ์
ตั้งค่าไลบรารีของไคลเอ็นต์
สำหรับ Maven
<!-- pom.xml -->
<dependency>
<groupId>com.google.api-ads</groupId>
<artifactId>ad-manager</artifactId>
<version>0.1.0</version>
</dependency>
สำหรับ Gradle
implementation 'com.google.api-ads:ad-manager:0.1.0'
ติดตั้งไลบรารีของไคลเอ็นต์จาก PyPi
pip install google-ads-admanager
ติดตั้งไลบรารีของไคลเอ็นต์จาก NuGet
จาก .NET CLI ให้ทำดังนี้
dotnet add package Google.Ads.AdManager.V1 --version 1.0.0-beta01
ใช้เป็นข้อมูลอ้างอิงแพ็กเกจ
<PackageReference Include="Google.Ads.AdManager.V1" Version="1.0.0-beta01" />
ติดตั้งไลบรารีของไคลเอ็นต์จาก Composer
composer require googleads/ad-manager
ติดตั้งไลบรารีของไคลเอ็นต์จาก RubyGems
Gemfile:
gem 'google-ads-ad_manager', '~> 0.2.0'
ติดตั้ง
gem install google-ads-ad_manager
ติดตั้งไลบรารีของไคลเอ็นต์จาก npm
จากบรรทัดคำสั่ง ให้ทำดังนี้
npm install @google-ads/admanager
ใช้เป็นข้อมูลอ้างอิงแพ็กเกจ
// package.json
"dependencies": {
"@google-ads/admanager": "^0.1.0"
}
ส่งคำขอแรก
import com.google.ads.admanager.v1.GetNetworkRequest;
import com.google.ads.admanager.v1.Network;
import com.google.ads.admanager.v1.NetworkName;
import com.google.ads.admanager.v1.NetworkServiceClient;
public class SyncGetNetwork {
public static void main(String[] args) throws Exception {
syncGetNetwork();
}
public static void syncGetNetwork() throws Exception {
try (NetworkServiceClient networkServiceClient = NetworkServiceClient.create()) {
GetNetworkRequest request =
GetNetworkRequest.newBuilder()
.setName(NetworkName.of("NETWORK_CODE ").toString())
.build();
Network response = networkServiceClient.getNetwork(request);
}
}
}
ดูตัวอย่างเพิ่มเติมได้ใน GitHub ดูข้อมูลเพิ่มเติมเกี่ยวกับไลบรารีไคลเอ็นต์ได้ที่คู่มือ Java
from google.ads import admanager_v1
def sample_get_network():
# Create a client
client = admanager_v1.NetworkServiceClient()
# Initialize request argument(s)
request = admanager_v1.GetNetworkRequest(
name="networks/NETWORK_CODE ",
)
# Make the request
response = client.get_network(request=request)
# Handle the response
print(response)
ดูตัวอย่างเพิ่มเติมได้ใน GitHub ดูข้อมูลเพิ่มเติมเกี่ยวกับไลบรารีของไคลเอ็นต์ได้ที่คู่มือ Python
using Google.Ads.AdManager.V1;
public sealed partial class GeneratedNetworkServiceClientSnippets
{
public void GetNetwork()
{
// Create client
NetworkServiceClient networkServiceClient = NetworkServiceClient.Create();
// Initialize request argument(s)
string name = "networks/NETWORK_CODE ";
// Make the request
Network response = networkServiceClient.GetNetwork(name);
}
}
ดูตัวอย่างเพิ่มเติมได้ใน GitHub ดูข้อมูลเพิ่มเติมเกี่ยวกับไลบรารีของไคลเอ็นต์ได้ที่คู่มือ .NET
<?php
use Google\Ads\AdManager\V1\Client\NetworkServiceClient;
use Google\Ads\AdManager\V1\GetNetworkRequest;
use Google\Ads\AdManager\V1\Network;
use Google\ApiCore\ApiException;
/**
* API to retrieve a Network object.
*
* @param string $formattedName Resource name of Network.
* Format: networks/{network_code}
* Please see {@see NetworkServiceClient::networkName()} for help formatting this field.
*/
function get_network_sample(string $formattedName): void
{
// Create a client.
$networkServiceClient = new NetworkServiceClient();
// Prepare the request message.
$request = (new GetNetworkRequest())
->setName($formattedName);
// Call the API and handle any network failures.
try {
/** @var Network $response */
$response = $networkServiceClient->getNetwork($request);
printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString());
} catch (ApiException $ex) {
printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage());
}
}
/**
* Helper to execute the sample.
*
*/
function callSample(): void
{
$formattedName = NetworkServiceClient::networkName('NETWORK_CODE ');
get_network_sample($formattedName);
}
ดูตัวอย่างเพิ่มเติมได้ใน GitHub
require "google/ads/ad_manager/v1"
def get_network
# Create a client object. The client can be reused for multiple calls.
client = Google::Ads::AdManager::V1::NetworkService::Rest::Client.new
# Create a request. To set request fields, pass in keyword arguments.
request = Google::Ads::AdManager::V1::GetNetworkRequest.new(:name => 'networks/NETWORK_CODE )'
# Call the get_network method.
result = client.get_network request
# The returned object is of type Google::Ads::AdManager::V1::Network.
p result
end
ดูตัวอย่างเพิ่มเติมได้ใน GitHub
// Resource name of the Network
const name = 'networks/NETWORK_CODE '
// Imports the Admanager library
const {NetworkServiceClient} = require('@google-ads/admanager').v1;
// Instantiates a client
const admanagerClient = new NetworkServiceClient();
async function callGetNetwork() {
// Construct request
const request = {
name,
};
// Run request
const response = await admanagerClient.getNetwork(request);
console.log(response);
}
callGetNetwork();
ดูตัวอย่างเพิ่มเติมได้ใน GitHub
curl -H "Authorization: Bearer $(gcloud auth application-default print-access-token)" \
https://admanager.googleapis.com/v1/networks/NETWORK_CODE