ติดตั้งและกำหนดค่าไคลเอ็นต์
จัดทุกอย่างให้เป็นระเบียบอยู่เสมอด้วยคอลเล็กชัน
บันทึกและจัดหมวดหมู่เนื้อหาตามค่ากำหนดของคุณ
เราขอแนะนำให้ใช้ไลบรารีของไคลเอ็นต์ Google API ร่วมกับ Bid Manager API เพื่อให้คุณ
จะไม่ต้องประมวลผลคำขอและการตอบกลับ HTTP ด้วยตนเอง Google API
ไลบรารีของไคลเอ็นต์จะให้การผสานรวมภาษาที่ดีกว่า ความปลอดภัยที่ดีขึ้น และ
การสนับสนุนสำหรับการโทรที่ต้องมีการให้สิทธิ์จากผู้ใช้
Bid Manager API สร้างขึ้นจาก HTTP และ JSON หากต้องการดำเนินการตามคำขอ
และการตอบกลับด้วยตนเอง คุณจะใช้ไคลเอ็นต์ HTTP มาตรฐานใดก็ได้
ติดตั้งไลบรารีของไคลเอ็นต์
เรามีไลบรารีไคลเอ็นต์ที่รองรับ Bid Manager API ด้วยสิ่งต่างๆ มากมาย
ภาษาโปรแกรม สำหรับรายการไลบรารีของไคลเอ็นต์ทั้งหมด โปรดดูตัวอย่างและ
แท็บคลัง
คู่มือนักพัฒนาซอฟต์แวร์ Bid Manager API ให้ข้อมูลโค้ดสำหรับ 3 สิ่งต่อไปนี้
ภาษา:
ดูตัวอย่างการผสานรวมทั้งหมดในภาษาเหล่านี้ได้ที่ตัวอย่าง Bid Manager API ของเรา
ที่เก็บ GitHub
ใช้ข้อมูลเข้าสู่ระบบ OAuth 2.0 และไคลเอ็นต์ที่ติดตั้งไว้
คุณก็พร้อมใช้ Bid Manager API แล้ว วิธีการมีดังนี้
ให้สิทธิ์และกำหนดค่าไคลเอ็นต์
Java
นำเข้าไลบรารีที่จำเป็น
import static java.nio.charset.StandardCharsets.UTF_8;
import com.google.api.client.auth.oauth2.Credential;
import com.google.api.client.extensions.java6.auth.oauth2.AuthorizationCodeInstalledApp;
import com.google.api.client.extensions.jetty.auth.oauth2.LocalServerReceiver;
import com.google.api.client.googleapis.auth.oauth2.GoogleAuthorizationCodeFlow;
import com.google.api.client.googleapis.auth.oauth2.GoogleClientSecrets;
import com.google.api.client.googleapis.util.Utils;
import com.google.api.services.doubleclickbidmanager.DoubleClickBidManager;
import java.io.Reader;
import java.nio.file.Files;
import java.nio.file.Paths;
โหลดไฟล์รหัสลับไคลเอ็นต์และสร้างข้อมูลเข้าสู่ระบบการให้สิทธิ์
ครั้งแรกที่ดำเนินการขั้นตอนนี้ ระบบจะขอให้คุณยอมรับการให้สิทธิ์
ในเบราว์เซอร์ ก่อนที่จะยอมรับ โปรดตรวจสอบว่าคุณได้ลงชื่อเข้าใช้ด้วย
บัญชี Google ที่มีสิทธิ์เข้าถึงดิสเพลย์และ วิดีโอ 360 แอปของคุณจะได้รับอนุญาต
เพื่อเข้าถึงข้อมูลในนามของบัญชีที่ลงชื่อเข้าใช้อยู่
// Read client secrets file.
GoogleClientSecrets clientSecrets;
try (Reader reader = Files.newBufferedReader(Paths.get(path-to-client-secrets-file), UTF_8)) {
clientSecrets = GoogleClientSecrets.load(Utils.getDefaultJsonFactory(), reader);
}
// Generate authorization credentials.
// Set up the authorization code flow.
GoogleAuthorizationCodeFlow flow =
new GoogleAuthorizationCodeFlow.Builder(
Utils.getDefaultTransport(),
Utils.getDefaultJsonFactory(),
clientSecrets,
oauth-scopes)
.build();
Credential credential =
new AuthorizationCodeInstalledApp(flow, new LocalServerReceiver()).authorize("user");
สร้างไคลเอ็นต์ API ที่ได้รับอนุญาต
// Create authorized API client.
DoubleClickBidManager service =
new DoubleClickBidManager.Builder(credential.getTransport(), credential.getJsonFactory(), credential)
.setApplicationName("bidmanager-java-installed-app-sample")
.build();
Python
นำเข้าไลบรารีที่จำเป็น
from google_auth_oauthlib.flow import InstalledAppFlow
from googleapiclient import discovery
โหลดไฟล์รหัสลับไคลเอ็นต์และสร้างข้อมูลเข้าสู่ระบบการให้สิทธิ์
ครั้งแรกที่ดำเนินการขั้นตอนนี้ ระบบจะขอให้คุณยอมรับการให้สิทธิ์
ในเบราว์เซอร์ ก่อนที่จะยอมรับ โปรดตรวจสอบว่าคุณได้ลงชื่อเข้าใช้ด้วย
บัญชี Google ที่มีสิทธิ์เข้าถึงดิสเพลย์และ วิดีโอ 360 แอปของคุณจะได้รับอนุญาต
เพื่อเข้าถึงข้อมูลในนามของบัญชีที่ลงชื่อเข้าใช้อยู่
# Set up a flow object to create the credentials using the
# client secrets file and OAuth scopes.
credentials = InstalledAppFlow.from_client_secrets_file(
path-to-client-secrets-file, oauth-scopes).run_local_server()
สร้างไคลเอ็นต์ API ที่ได้รับอนุญาต
# Build the discovery document URL.
discovery_url = f'https://doubleclickbidmanager.googleapis.com/$discovery/rest?version=v2'
# Build the API service.
service = discovery.build(
'doubleclickbidmanager',
'v2',
discoveryServiceUrl=discovery_url,
credentials=credentials)
PHP
ตัวอย่างนี้สมมติว่าคุณกำลังเรียกใช้ PHP กับเว็บเซิร์ฟเวอร์ภายในและ
ได้กำหนดค่าข้อมูลเข้าสู่ระบบของคุณให้เปลี่ยนเส้นทางไปยังหน้าเว็บที่เกี่ยวข้อง สำหรับ
เช่น โค้ดนี้ในไฟล์ index.php
สามารถเรียกใช้ได้โดยใช้
คำสั่งและข้อมูลเข้าสู่ระบบที่กำหนดค่าไว้ให้เปลี่ยนเส้นทางไปยัง http://localhost:8000
หลังจาก
การตรวจสอบสิทธิ์:
php -S localhost:8000 -t ./
ดาวน์โหลดและติดตั้งไคลเอ็นต์ Google API PHP
วิธีที่แนะนำคือการใช้คอมโพสเซอร์ ดังนี้
composer require google/apiclient:^2.12.1
เมื่อติดตั้งแล้ว โปรดตรวจสอบว่าได้รวมตัวโหลดอัตโนมัติแล้ว
require_once '/path/to/your-project/vendor/autoload.php';
สร้างออบเจ็กต์ Google_Client
$client = new Google_Client();
ตั้งค่าไคลเอ็นต์ เปลี่ยนเส้นทางไปยัง URL การตรวจสอบสิทธิ์หากจำเป็น แล้วเรียกโทเค็นเพื่อการเข้าถึง
ครั้งแรกที่ดำเนินการขั้นตอนนี้ ระบบจะขอให้คุณยอมรับการให้สิทธิ์
ในเบราว์เซอร์ ก่อนที่จะยอมรับ โปรดตรวจสอบว่าคุณได้ลงชื่อเข้าใช้ด้วย
บัญชี Google ที่มีสิทธิ์เข้าถึงดิสเพลย์และ วิดีโอ 360 แอปของคุณจะได้รับอนุญาต
เพื่อเข้าถึงข้อมูลในนามของบัญชีที่ลงชื่อเข้าใช้อยู่
// Set up the client.
$client->setApplicationName('DBM API PHP Samples');
$client->addScope(oauth-scope);
$client->setAccessType('offline');
$client->setAuthConfigFile(path-to-client-secrets-file);
// If the code is passed, authenticate. If not, redirect to authentication page.
if (isset($_GET['code'])) {
$client->authenticate($_GET['code']);
} else {
$authUrl = $client->createAuthUrl();
header('Location: ' . $authUrl);
}
// Exchange authorization code for an access token.
$accessToken = $client->getAccessToken();
$client->setAccessToken($accessToken);
สร้างไคลเอ็นต์สำหรับดิสเพลย์และ บริการ API ของ Video 360
$service = new Google_Service_DoubleClickBidManager($client);
เนื้อหาของหน้าเว็บนี้ได้รับอนุญาตภายใต้ใบอนุญาตที่ต้องระบุที่มาของครีเอทีฟคอมมอนส์ 4.0 และตัวอย่างโค้ดได้รับอนุญาตภายใต้ใบอนุญาต Apache 2.0 เว้นแต่จะระบุไว้เป็นอย่างอื่น โปรดดูรายละเอียดที่นโยบายเว็บไซต์ Google Developers Java เป็นเครื่องหมายการค้าจดทะเบียนของ Oracle และ/หรือบริษัทในเครือ
อัปเดตล่าสุด 2025-08-31 UTC
[null,null,["อัปเดตล่าสุด 2025-08-31 UTC"],[[["\u003cp\u003eThe Bid Manager API is built on HTTP and JSON, and Google recommends using their client libraries for easier integration and security.\u003c/p\u003e\n"],["\u003cp\u003eClient libraries for the Bid Manager API are available in various programming languages, including Java, Python, and PHP, with code snippets and examples provided.\u003c/p\u003e\n"],["\u003cp\u003eTo use the API, you need OAuth 2.0 credentials and an installed client library, and you can configure your client using provided code samples for Java, Python, and PHP.\u003c/p\u003e\n"],["\u003cp\u003eThe provided code samples demonstrate how to import libraries, load client secrets, generate authorization credentials, and create authorized API clients in Java, Python, and PHP.\u003c/p\u003e\n"]]],["The document outlines using Google API client libraries for the Bid Manager API, built on HTTP and JSON. It details the process for Java, Python, and PHP. Key steps include: installing a client library, importing necessary libraries, loading client secrets, generating OAuth 2.0 authorization credentials, and creating an authorized API client. The process involves browser-based authorization prompts, ensuring the user is signed into a Google account with Display & Video 360 access. Specific code examples are given.\n"],null,["# Install and configure your client\n\nWe recommend using the Google API client libraries with the Bid Manager API, so you\ndon't have to manually process HTTP requests and responses. The Google API\nclient libraries can provide better language integration, improved security, and\nsupport for making calls that require user authorization.\n\nThe Bid Manager API is built on HTTP and JSON. If you prefer to process requests\nand responses manually, you can use any standard HTTP client.\n\nInstall a client library\n------------------------\n\nWe offer client libraries that support the Bid Manager API in a variety of\nprogramming languages. For a full list of client libraries, see the [Samples and\nlibraries tab](/bid-manager/libraries).\n\nThe Bid Manager API developer guides provide code snippets for the following three\nlanguages:\n\n- [Java](//github.com/googleads/googleads-bidmanager-examples/blob/main/java/v2/README.md)\n- [Python](//github.com/googleads/googleads-bidmanager-examples/blob/main/python/v2/README.md)\n- [PHP](//github.com/googleads/googleads-bidmanager-examples/blob/main/php/v2/README.md)\n\nFor full integration examples in these languages, see our [Bid Manager API examples\nGitHub repository](//github.com/googleads/googleads-bidmanager-examples).\n\nConfigure your client\n---------------------\n\nWith [OAuth 2.0 credentials](/bid-manager/guides/get-started/generate-credentials#generate_credentials) and an [installed client\nlibrary](#install_a_client_library), you're ready to use the Bid Manager API. Here's how to\nauthorize and configure your client: \n\n### Java\n\n1. **Import the necessary libraries.**\n\n ```java\n import static java.nio.charset.StandardCharsets.UTF_8;\n import com.google.api.client.auth.oauth2.Credential;\n import com.google.api.client.extensions.java6.auth.oauth2.AuthorizationCodeInstalledApp;\n import com.google.api.client.extensions.jetty.auth.oauth2.LocalServerReceiver;\n import com.google.api.client.googleapis.auth.oauth2.GoogleAuthorizationCodeFlow;\n import com.google.api.client.googleapis.auth.oauth2.GoogleClientSecrets;\n import com.google.api.client.googleapis.util.Utils;\n import com.google.api.services.doubleclickbidmanager.DoubleClickBidManager;\n import java.io.Reader;\n import java.nio.file.Files;\n import java.nio.file.Paths;\n ```\n2. **Load the client secrets file and generate authorization credentials.**\n\n\n The first time you perform this step, you are asked to accept an authorization\n prompt in your browser. Before accepting, make sure you're signed in with a\n Google Account that has access to Display \\& Video 360. Your app will be authorized\n to access data on behalf of whichever account is currently signed in.\n\n ```java\n // Read client secrets file.\n GoogleClientSecrets clientSecrets;\n try (Reader reader = Files.newBufferedReader(Paths.get(path-to-client-secrets-file), UTF_8)) {\n clientSecrets = GoogleClientSecrets.load(Utils.getDefaultJsonFactory(), reader);\n }\n\n // Generate authorization credentials.\n // Set up the authorization code flow.\n GoogleAuthorizationCodeFlow flow =\n new GoogleAuthorizationCodeFlow.Builder(\n Utils.getDefaultTransport(),\n Utils.getDefaultJsonFactory(),\n clientSecrets,\n oauth-scopes)\n .build();\n\n Credential credential =\n new AuthorizationCodeInstalledApp(flow, new LocalServerReceiver()).authorize(\"user\");\n ```\n3. **Create an authorized API client.**\n\n ```java\n // Create authorized API client.\n DoubleClickBidManager service =\n new DoubleClickBidManager.Builder(credential.getTransport(), credential.getJsonFactory(), credential)\n .setApplicationName(\"bidmanager-java-installed-app-sample\")\n .build();\n ```\n\n### Python\n\n1. **Import the necessary libraries.**\n\n ```python\n from google_auth_oauthlib.flow import InstalledAppFlow\n from googleapiclient import discovery\n ```\n2. **Load the client secrets file and generate authorization credentials.**\n\n\n The first time you perform this step, you are asked to accept an authorization\n prompt in your browser. Before accepting, make sure you're signed in with a\n Google Account that has access to Display \\& Video 360. Your app will be authorized\n to access data on behalf of whichever account is currently signed in.\n\n ```python\n # Set up a flow object to create the credentials using the\n # client secrets file and OAuth scopes.\n credentials = InstalledAppFlow.from_client_secrets_file(\n path-to-client-secrets-file, oauth-scopes).run_local_server()\n ```\n3. **Create an authorized API client.**\n\n ```python\n # Build the discovery document URL.\n discovery_url = f'https://doubleclickbidmanager.googleapis.com/$discovery/rest?version=v2'\n\n # Build the API service.\n service = discovery.build(\n 'doubleclickbidmanager',\n 'v2',\n discoveryServiceUrl=discovery_url,\n credentials=credentials)\n ```\n\n### PHP\n\n\nThis sample assumes that you are running the PHP with a built-in web server and\nhave configured your credentials to redirect to the relevant web page. For\nexample, this code, in an `index.php` file, can be run using the following\ncommand and credentials configured to redirect to `http://localhost:8000` after\nauthentication: \n\n```php\nphp -S localhost:8000 -t ./\n```\n\n\u003cbr /\u003e\n\n1. **Download and install the Google API PHP Client.**\n\n The preferred method is via [Composer](https://getcomposer.org/): \n\n ```php\n composer require google/apiclient:^2.12.1\n ```\n\n \u003cbr /\u003e\n\n Once installed, be sure to include the autoloader \n\n ```php\n require_once '/path/to/your-project/vendor/autoload.php';\n ```\n\n \u003cbr /\u003e\n\n2. **Create a Google_Client object.**\n\n ```php\n $client = new Google_Client();\n ```\n3. **Set up the client, redirect to authentication URL if needed, and retrieve an access token.**\n\n\n The first time you perform this step, you are asked to accept an authorization\n prompt in your browser. Before accepting, make sure you're signed in with a\n Google Account that has access to Display \\& Video 360. Your app will be authorized\n to access data on behalf of whichever account is currently signed in.\n\n ```php\n // Set up the client.\n $client-\u003esetApplicationName('DBM API PHP Samples');\n $client-\u003eaddScope(\u003cvar translate=\"no\"\u003eoauth-scope\u003c/var\u003e);\n $client-\u003esetAccessType('offline');\n $client-\u003esetAuthConfigFile(\u003cvar translate=\"no\"\u003epath-to-client-secrets-file\u003c/var\u003e);\n\n // If the code is passed, authenticate. If not, redirect to authentication page.\n if (isset($_GET['code'])) {\n $client-\u003eauthenticate($_GET['code']);\n } else {\n $authUrl = $client-\u003ecreateAuthUrl();\n header('Location: ' . $authUrl);\n }\n\n // Exchange authorization code for an access token.\n $accessToken = $client-\u003egetAccessToken();\n $client-\u003esetAccessToken($accessToken);\n ```\n4. **Construct a client for the Display \\& Video 360 API service.**\n\n ```php\n $service = new Google_Service_DoubleClickBidManager($client);\n ```"]]