بدء استخدام واجهة برمجة التطبيقات
تنظيم صفحاتك في مجموعات
يمكنك حفظ المحتوى وتصنيفه حسب إعداداتك المفضّلة.
يشرح هذا المستند كيفية البدء في كتابة التطبيقات التي تستخدم
واجهة برمجة تطبيقات Google Bid Manager. تتيح لك واجهة برمجة التطبيقات إدارة طلبات البحث واسترداد البيانات الوصفية في التقارير.
الإصدار 2 من Bid Manager API هو أحدث واجهة برمجة تطبيقات متاحة ومقترَحة.
.
1. قبل البدء
إذا لم تكن على دراية بمفاهيم "مساحة العرض والفيديو 360" من Google، يمكنك قراءة مقالات مركز مساعدة "مساحة العرض والفيديو 360" ومحاولة استخدام واجهة المستخدِم.
2. الاستعداد للمصادقة
لبدء استخدام Bid Manager API، عليك أولاً استخدام أداة الإعداد التي تقدّم لك إرشادات خلال عملية إنشاء المشروع في وحدة تحكّم Google API وتفعيل واجهة برمجة التطبيقات وإنشاء بيانات الاعتماد.
إذا لم يسبق لك إجراء ذلك، يمكنك إنشاء بيانات اعتماد OAuth 2.0 من خلال النقر على
إنشاء بيانات الاعتماد > معرِّف عميل OAuth. بعد إنشاء
بيانات الاعتماد، يمكنك الاطّلاع على معرّف العميل في صفحة
بيانات الاعتماد. انقر على
رقم تعريف العميل للاطّلاع على التفاصيل، مثل مفتاح سر العميل وعناوين URL لإعادة التوجيه وعنوان ملف JavaScript
المنشأ وعنوان البريد الإلكتروني.
لمزيد من المعلومات، يُرجى مراجعة
الموافقة على الطلبات:
3- استدعاء Bid Manager API
توفر علامات التبويب أدناه نقاط بدايات سريعة للترميز بلغات مختلفة. يمكن أيضًا العثور على رمز نموذجي مشابه في مستودع عيّنات 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 com.google.api.services.doubleclickbidmanager.model.ListQueriesResponse;
import com.google.api.services.doubleclickbidmanager.model.Query;
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");
أنشئ برنامج واجهة برمجة تطبيقات معتمدًا.
// Create authorized API client.
DoubleClickBidManager service =
new DoubleClickBidManager.Builder(credential.getTransport(), credential.getJsonFactory(), credential)
.setApplicationName("bidmanager-java-installed-app-sample")
.build();
نفِّذ عملية.
// Perform an operation.
// Call the API, getting a list of 10 queries.
ListQueriesResponse queriesResponse = service.queries().list().setPageSize(10).execute();
// Print them out.
System.out.println("Id\t\tName");
if (queriesResponse.getQueries().size() > 0) {
for (int i = 0; i < queriesResponse.getQueries().size(); i++) {
Query currentQuery = queriesResponse.getQueries().get(i);
System.out.printf(
"%s\t%s%n",
currentQuery.getQueryId(),
currentQuery.getMetadata().getTitle());
}
} else {
System.out.println("No queries exist.");
}
لمزيد من المعلومات التفصيلية عن استخدام واجهة برمجة تطبيقات إدارة عرض السعر مع Java،
يُرجى الرجوع إلى
قراءة
ملف في
أمثلة على واجهة برمجة تطبيقات "إدارة عرض السعر"
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()
أنشئ برنامج واجهة برمجة تطبيقات معتمدًا.
# 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)
تنفيذ عملية:
# Build and execute queries.listqueries request.
response = service.queries().list(pageSize='10').execute()
# Print queries out.
if 'queries' in response:
print('Id\t\tName')
for query in response['queries']:
print('%s\t%s' % (query['queryId'], query['metadata']['title']))
else:
print('No queries exist.')
للحصول على معلومات أكثر تفصيلاً عن استخدام Bid Manager API مع Python،
يُرجى الرجوع إلىملف README
في أمثلة Bid Manager API.
PHP
يفترض هذا المثال أنّك تستخدم لغة PHP مع خادم ويب مضمّن و
أنّك أعددت بيانات الاعتماد لإعادة التوجيه إلى صفحة الويب ذات الصلة. بالنسبة
على سبيل المثال، يمكن تنفيذ هذا الرمز في ملف index.php
باستخدام
الأمر وبيانات الاعتماد التي تم ضبطها لإعادة التوجيه إلى http://localhost:8000
بعد
المصادقة:
php -S localhost:8000 -t ./
عليك تنزيل برنامج Google API PHP وتثبيته.
الطريقة المفضّلة هي عبر Composer:
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);
إنشاء برنامج للشبكة الإعلانية خدمة Video 360 API:
$service = new Google_Service_DoubleClickBidManager($client);
تنفيذ عملية:
// Configure params for the Queries.listqueries request.
$optParams = array('pageSize' => 10);
// Execute the request.
$result = $service->queries->listQueries($optParams);
// Print the retrieved queries.
if (!empty($result->getQueries())) {
print('<pre><p>Id Name</p>');
foreach ($result->getQueries() as $query) {
printf('<p>%s %s</p>', $query->queryId, $query->metadata->title);
}
print('</pre>');
} else {
print '<p>No queries exist.</p>';
}
للحصول على معلومات أكثر تفصيلاً عن استخدام Bid Manager API مع PHP،
راجِع ملفّ
README
في أمثلة Bid Manager API.
4. الخطوات التالية
الآن بعد أن أصبحت لديك مكتبة عملاء جاهزة وقيد التشغيل، استكشف المرجع
التوثيق والبدء في إنشاء التنفيذ.
تتوفر أيضًا أدلة إضافية على
واستخدام التقارير المُجدوَلة
أو
اتّباع أفضل الممارسات المتعلّقة بإعداد التقارير
إنّ محتوى هذه الصفحة مرخّص بموجب ترخيص Creative Commons Attribution 4.0 ما لم يُنصّ على خلاف ذلك، ونماذج الرموز مرخّصة بموجب ترخيص Apache 2.0. للاطّلاع على التفاصيل، يُرجى مراجعة سياسات موقع Google Developers. إنّ Java هي علامة تجارية مسجَّلة لشركة Oracle و/أو شركائها التابعين.
تاريخ التعديل الأخير: 2025-08-31 (حسب التوقيت العالمي المتفَّق عليه)
[null,null,["تاريخ التعديل الأخير: 2025-08-31 (حسب التوقيت العالمي المتفَّق عليه)"],[[["\u003cp\u003eThe Google Bid Manager API allows you to programmatically manage queries and retrieve report metadata, streamlining your workflow.\u003c/p\u003e\n"],["\u003cp\u003eBefore using the API, ensure familiarity with Display & Video 360 by exploring its help center and user interface.\u003c/p\u003e\n"],["\u003cp\u003eTo begin, set up authentication using the provided setup tool, enabling the API and generating necessary credentials for secure access.\u003c/p\u003e\n"],["\u003cp\u003eUtilize the provided quickstarts and code examples for Java, Python, and PHP to integrate the API into your applications efficiently.\u003c/p\u003e\n"],["\u003cp\u003eAfter setup, delve into the reference documentation and explore guides on scheduled reports and reporting best practices for optimal utilization.\u003c/p\u003e\n"]]],[],null,["This document explains how to get started writing apps that use the\nGoogle Bid Manager API. The API lets you manage\n[Queries](/bid-manager/reference/rest/v2/queries) and retrieve\n[Report](/bid-manager/reference/rest/v2/queries.reports) metadata.\n\nBid Manager API v2 is the latest available and recommended\nversion.\n\n1. Before you start\n\nIf you're unfamiliar with Google Display \\& Video 360 concepts, read the\n[Display \\& Video 360 Help Center](//support.google.com/displayvideo/) and\nexperiment with the [UI](//displayvideo.google.com/).\n\n2. Prepare for authentication\n\nTo get started using Bid Manager API, you need to first\n[use\nthe setup tool](https://console.cloud.google.com/start/api?id=doubleclickbidmanager&credential=client_key), which guides you through creating a project in the\nGoogle API Console, enabling the API, and creating credentials.\nIf you haven't done so already, create your OAuth 2.0 credentials by clicking **Create credentials \\\u003e OAuth client ID** . After you've created the credentials, you can see your client ID on the **Credentials** page. Click the client ID for details, such as client secret, redirect URIs, JavaScript origins address, and email address.\n\nFor more information, see\n[Authorize Requests](/bid-manager/how-tos/authorizing).\n\n3. Call the Bid Manager API\n\nThe tabs below provide quickstarts for coding in various languages. Similar\nsample code can also be found in the\n[Bid Manager API Examples](//github.com/googleads/googleads-bidmanager-examples)\nrepo. \n\nJava\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 com.google.api.services.doubleclickbidmanager.model.ListQueriesResponse;\n import com.google.api.services.doubleclickbidmanager.model.Query;\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 ```\n4. **Perform an operation.**\n\n ```java\n // Perform an operation.\n // Call the API, getting a list of 10 queries.\n ListQueriesResponse queriesResponse = service.queries().list().setPageSize(10).execute();\n\n // Print them out.\n System.out.println(\"Id\\t\\tName\");\n if (queriesResponse.getQueries().size() \u003e 0) {\n for (int i = 0; i \u003c queriesResponse.getQueries().size(); i++) {\n Query currentQuery = queriesResponse.getQueries().get(i);\n System.out.printf(\n \"%s\\t%s%n\",\n currentQuery.getQueryId(),\n currentQuery.getMetadata().getTitle());\n }\n } else {\n System.out.println(\"No queries exist.\");\n }\n ```\n\nFor more detailed information about using the Bid Manager API with Java,\nrefer to the\n[README](//github.com/googleads/googleads-bidmanager-examples/blob/HEAD/java/README.md)\nfile in the\n[Bid Manager API examples](//github.com/googleads/googleads-bidmanager-examples).\n\nPython\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 ```\n4. **Perform an operation.**\n\n ```python\n # Build and execute queries.listqueries request.\n response = service.queries().list(pageSize='10').execute()\n\n # Print queries out.\n if 'queries' in response:\n print('Id\\t\\tName')\n for query in response['queries']:\n print('%s\\t%s' % (query['queryId'], query['metadata']['title']))\n else:\n print('No queries exist.')\n ```\n\nFor more detailed information about using the Bid Manager API with Python,\nrefer to the\n[README](//github.com/googleads/googleads-bidmanager-examples/blob/HEAD/python/README.md)\nfile in the\n[Bid Manager API examples](//github.com/googleads/googleads-bidmanager-examples).\n\nPHP\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 ```\n5. **Perform an operation.**\n\n ```php\n // Configure params for the Queries.listqueries request.\n $optParams = array('pageSize' =\u003e 10);\n\n // Execute the request.\n $result = $service-\u003equeries-\u003elistQueries($optParams);\n\n // Print the retrieved queries.\n if (!empty($result-\u003egetQueries())) {\n print('\u003cpre\u003e\u003cp\u003eId Name\u003c/p\u003e');\n foreach ($result-\u003egetQueries() as $query) {\n printf('\u003cp\u003e%s %s\u003c/p\u003e', $query-\u003equeryId, $query-\u003emetadata-\u003etitle);\n }\n print('\u003c/pre\u003e');\n } else {\n print '\u003cp\u003eNo queries exist.\u003c/p\u003e';\n }\n ```\n\nFor more detailed information about using the Bid Manager API with PHP,\nrefer to the\n[README](//github.com/googleads/googleads-bidmanager-examples/blob/HEAD/php/README.md)\nfile in the\n[Bid Manager API examples](//github.com/googleads/googleads-bidmanager-examples).\n\n4. Next steps\n\nNow that you have a client library up and running, explore the reference\ndocumentation and begin building out your implementation.\n\nAdditional guides are also available on\n[utilizing scheduled reports](/bid-manager/guides/scheduled-reports/overview)\nand\n[following reporting best practices](/bid-manager/guides/scheduled-reports/best-practices)."]]