از 8 سپتامبر 2025 ، هر مورد خط جدید باید اعلام کند که آیا تبلیغات سیاسی اتحادیه اروپا (EU) را ارائه می دهد یا خیر. Display & Video 360 API و بارگذاریهای SDF که اعلانها را ارائه نمیکنند با شکست مواجه میشوند. برای جزئیات بیشتر در مورد نحوه به روز رسانی یکپارچه سازی خود برای ایجاد این اعلامیه، به صفحه لغو اعتبار ما مراجعه کنید.
با مجموعهها، منظم بمانید ذخیره و طبقهبندی محتوا براساس اولویتهای شما.
با ایجاد اعتبارنامه OAuth 2.0 و نصب کتابخانه سرویس گیرنده ، آماده شروع استفاده از Display & Video 360 API هستید. با دنبال کردن راه اندازی سریع زیر، نحوه مجوز، پیکربندی مشتری و اولین درخواست خود را بیاموزید.
فایل اسرار مشتری را بارگیری کنید و اعتبارنامه مجوز ایجاد کنید.
اولین باری که این مرحله را انجام میدهید، از شما خواسته میشود که درخواست مجوز را در مرورگر خود بپذیرید. قبل از پذیرش، مطمئن شوید که با یک حساب Google وارد شدهاید که به Display & Video 360 دسترسی دارد. برنامه شما مجاز خواهد بود از طرف هر حسابی که در حال حاضر وارد سیستم شده است به دادهها دسترسی داشته باشد. برای جزئیات بیشتر در مورد مجوزهای کاربر Display & Video 360 به راهنمای درخواستهای مجوز ما مراجعه کنید.
// Read client secrets file.GoogleClientSecretsclientSecrets;try(Readerreader=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.GoogleAuthorizationCodeFlowflow=newGoogleAuthorizationCodeFlow.Builder(Utils.getDefaultTransport(),Utils.getDefaultJsonFactory(),clientSecrets,oauth-scopes).build();Credentialcredential=newAuthorizationCodeInstalledApp(flow,newLocalServerReceiver()).authorize("user");
یک کلاینت مجاز API ایجاد کنید.
// Create authorized API client.DisplayVideoservice=newDisplayVideo.Builder(credential.getTransport(),credential.getJsonFactory(),credential).setApplicationName("displayvideo-java-installed-app-sample").build();
یک عملیات انجام دهید.
// Perform an operation.// Retrieve and print the first ten advertisers under a partner.ListAdvertisersResponseresponse=service.advertisers().list().setPartnerId(partner-id).setPageSize(10).execute();if(response.getAdvertisers().size() > 0){for(inti=0;i < response.getAdvertisers().size();i++){System.out.printf("ID: %s Display Name: %s%n",response.getAdvertisers().get(i).getAdvertiserId(),response.getAdvertisers().get(i).getDisplayName());}}else{System.out.print("No advertisers found.");}
فایل اسرار مشتری را بارگیری کنید و اعتبارنامه مجوز ایجاد کنید.
اولین باری که این مرحله را انجام میدهید، از شما خواسته میشود که درخواست مجوز را در مرورگر خود بپذیرید. قبل از پذیرش، مطمئن شوید که با یک حساب Google وارد شدهاید که به Display & Video 360 دسترسی دارد. برنامه شما مجاز خواهد بود از طرف هر حسابی که در حال حاضر وارد سیستم شده است به دادهها دسترسی داشته باشد. برای جزئیات بیشتر در مورد مجوزهای کاربر Display & Video 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://displayvideo.googleapis.com/$discovery/rest?version=v4'# Build the API service.service=discovery.build('displayvideo','v4',discoveryServiceUrl=discovery_url,credentials=credentials)
این نمونه فرض می کند که شما PHP را با یک وب سرور داخلی اجرا می کنید و اعتبار خود را برای تغییر مسیر به صفحه وب مربوطه پیکربندی کرده اید. به عنوان مثال، این کد در یک فایل index.php ، می تواند با استفاده از دستور زیر و اعتبارنامه های پیکربندی شده برای تغییر مسیر به http://localhost:8000 پس از احراز هویت اجرا شود:
کلاینت را تنظیم کنید، در صورت نیاز به URL احراز هویت هدایت کنید و یک نشانه دسترسی را بازیابی کنید.
اولین باری که این مرحله را انجام میدهید، از شما خواسته میشود که درخواست مجوز را در مرورگر خود بپذیرید. قبل از پذیرش، مطمئن شوید که با یک حساب Google وارد شدهاید که به Display & Video 360 دسترسی دارد. برنامه شما مجاز خواهد بود از طرف هر حسابی که در حال حاضر وارد سیستم شده است به دادهها دسترسی داشته باشد. برای جزئیات بیشتر در مورد مجوزهای کاربر Display & Video 360 به راهنمای درخواستهای مجوز ما مراجعه کنید.
// Set up the client.$client->setApplicationName('DV360 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);
یک کلاینت برای سرویس Display & Video 360 API بسازید.
$service = new Google_Service_DisplayVideo($client);
یک عملیات انجام دهید.
// Configure params for the advertisers.list request.$optParams = array('pageSize' => 10, 'partnerId' => partner-id);// Execute the request.$result = $service->advertisers->listAdvertisers($optParams);// Print the retrieved advertisers.if (!empty($result->getAdvertisers())) { print('<pre>'); foreach ($result->getAdvertisers() as $advertiser) { printf('<p>ID: %s, Display Name: %s</p>', $advertiser->advertiserId, $advertiser->displayName); } print('</pre>');} else { print '<p>No advertisers found.</p>';}
تاریخ آخرین بهروزرسانی 2025-07-24 بهوقت ساعت هماهنگ جهانی.
[[["درک آسان","easyToUnderstand","thumb-up"],["مشکلم را برطرف کرد","solvedMyProblem","thumb-up"],["غیره","otherUp","thumb-up"]],[["اطلاعاتی که نیاز دارم وجود ندارد","missingTheInformationINeed","thumb-down"],["بیشازحد پیچیده/ مراحل بسیار زیاد","tooComplicatedTooManySteps","thumb-down"],["قدیمی","outOfDate","thumb-down"],["مشکل ترجمه","translationIssue","thumb-down"],["مشکل کد / نمونهها","samplesCodeIssue","thumb-down"],["غیره","otherDown","thumb-down"]],["تاریخ آخرین بهروزرسانی 2025-07-24 بهوقت ساعت هماهنگ جهانی."],[[["\u003cp\u003eThis quickstart guide demonstrates how to get started with the Display & Video 360 API using Java, Python, or PHP.\u003c/p\u003e\n"],["\u003cp\u003eBefore you begin, ensure you have OAuth 2.0 credentials and a compatible client library installed.\u003c/p\u003e\n"],["\u003cp\u003eThe guide provides step-by-step instructions on authorizing your client, configuring it, and executing your first API request.\u003c/p\u003e\n"],["\u003cp\u003eA simple example showcasing the retrieval of advertisers under a partner is included to illustrate the process.\u003c/p\u003e\n"],["\u003cp\u003eYou'll need a Google Account with Display & Video 360 access for authorization.\u003c/p\u003e\n"]]],[],null,["# Configure your client\n\nWith [OAuth 2.0 credentials created](/display-video/api/guides/getting-started/overview#prerequisites) and a [client library\ninstalled](/display-video/api/guides/getting-started/libraries), you're ready to start using the Display \\& Video 360 API.\nLearn how to authorize, configure your client, and make your first request by\nfollowing the quickstart below. \n\n### Java\n\n1. **Import the necessary libraries.**\n\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.displayvideo.v4.DisplayVideo;\n import com.google.api.services.displayvideo.v4.DisplayVideo.Advertisers;\n import com.google.api.services.displayvideo.v4.model.Advertiser;\n import com.google.api.services.displayvideo.v4.model.ListAdvertisersResponse;\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. See our\n [Authorize\n Requests](/display-video/api/guides/how-tos/authorizing#user_permissions) guide\n for more details on Display \\& Video 360 user permissions.\n\n // Read client secrets file.\n GoogleClientSecrets clientSecrets;\n try (Reader reader = Files.newBufferedReader(Paths.get(\u003cvar translate=\"no\"\u003e\u003cspan class=\"devsite-syntax-n\"\u003epath\u003c/span\u003e\u003cspan class=\"devsite-syntax-o\"\u003e-\u003c/span\u003e\u003cspan class=\"devsite-syntax-n\"\u003eto\u003c/span\u003e\u003cspan class=\"devsite-syntax-o\"\u003e-\u003c/span\u003e\u003cspan class=\"devsite-syntax-n\"\u003eclient\u003c/span\u003e\u003cspan class=\"devsite-syntax-o\"\u003e-\u003c/span\u003e\u003cspan class=\"devsite-syntax-n\"\u003esecrets\u003c/span\u003e\u003cspan class=\"devsite-syntax-o\"\u003e-\u003c/span\u003e\u003cspan class=\"devsite-syntax-n\"\u003efile\u003c/span\u003e\u003c/var\u003e), 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 \u003cvar translate=\"no\"\u003e\u003cspan class=\"devsite-syntax-n\"\u003eoauth\u003c/span\u003e\u003cspan class=\"devsite-syntax-o\"\u003e-\u003c/span\u003e\u003cspan class=\"devsite-syntax-n\"\u003escopes\u003c/span\u003e\u003c/var\u003e)\n .build();\n\n Credential credential =\n new AuthorizationCodeInstalledApp(flow, new LocalServerReceiver()).authorize(\"user\");\n\n3. **Create an authorized API client.**\n\n // Create authorized API client.\n DisplayVideo service =\n new DisplayVideo.Builder(credential.getTransport(), credential.getJsonFactory(), credential)\n .setApplicationName(\"displayvideo-java-installed-app-sample\")\n .build();\n\n4. **Perform an operation.**\n\n // Perform an operation.\n // Retrieve and print the first ten advertisers under a partner.\n ListAdvertisersResponse response =\n service\n .advertisers()\n .list()\n .setPartnerId(\u003cvar translate=\"no\"\u003e\u003cspan class=\"devsite-syntax-n\"\u003epartner\u003c/span\u003e\u003cspan class=\"devsite-syntax-o\"\u003e-\u003c/span\u003e\u003cspan class=\"devsite-syntax-n\"\u003eid\u003c/span\u003e\u003c/var\u003e)\n .setPageSize(10)\n .execute();\n if (response.getAdvertisers().size() \u003e 0) {\n for (int i = 0; i \u003c response.getAdvertisers().size(); i++) {\n System.out.printf(\n \"ID: %s Display Name: %s%n\",\n response.getAdvertisers().get(i).getAdvertiserId(),\n response.getAdvertisers().get(i).getDisplayName());\n }\n } else {\n System.out.print(\"No advertisers found.\");\n }\n\n### Python\n\n1. **Import the necessary libraries.**\n\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. See our\n [Authorize\n Requests](/display-video/api/guides/how-tos/authorizing#user_permissions) guide\n for more details on Display \\& Video 360 user permissions.\n\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 \u003cvar translate=\"no\"\u003e\u003cspan class=\"devsite-syntax-n\"\u003epath\u003c/span\u003e\u003cspan class=\"devsite-syntax-o\"\u003e-\u003c/span\u003e\u003cspan class=\"devsite-syntax-n\"\u003eto\u003c/span\u003e\u003cspan class=\"devsite-syntax-o\"\u003e-\u003c/span\u003e\u003cspan class=\"devsite-syntax-n\"\u003eclient\u003c/span\u003e\u003cspan class=\"devsite-syntax-o\"\u003e-\u003c/span\u003e\u003cspan class=\"devsite-syntax-n\"\u003esecrets\u003c/span\u003e\u003cspan class=\"devsite-syntax-o\"\u003e-\u003c/span\u003e\u003cspan class=\"devsite-syntax-n\"\u003efile\u003c/span\u003e\u003c/var\u003e, \u003cvar translate=\"no\"\u003e\u003cspan class=\"devsite-syntax-n\"\u003eoauth\u003c/span\u003e\u003cspan class=\"devsite-syntax-o\"\u003e-\u003c/span\u003e\u003cspan class=\"devsite-syntax-n\"\u003escopes\u003c/span\u003e\u003c/var\u003e).run_local_server()\n\n3. **Create an authorized API client.**\n\n # Build the discovery document URL.\n discovery_url = f'https://displayvideo.googleapis.com/$discovery/rest?version=v4'\n\n # Build the API service.\n service = discovery.build(\n 'displayvideo',\n 'v4',\n discoveryServiceUrl=discovery_url,\n credentials=credentials)\n\n4. **Perform an operation.**\n\n # Build advertisers.list request.\n request = service.advertisers().list(\n partnerId=\u003cvar translate=\"no\"\u003e\u003cspan class=\"devsite-syntax-n\"\u003epartner\u003c/span\u003e\u003cspan class=\"devsite-syntax-o\"\u003e-\u003c/span\u003e\u003cspan class=\"devsite-syntax-nb\"\u003eid\u003c/span\u003e\u003c/var\u003e, pageSize='10')\n\n # Execute request.\n response = request.execute()\n\n # Print response.\n if len(response['advertisers']) \u003e 0:\n for advertiser in response['advertisers']:\n print(f'ID: {advertiser[\"advertiserId\"]} Display Name: {advertiser[\"displayName\"]}')\n else:\n print('No advertisers found.')\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 -S localhost:8000 -t ./\n\n\u003cbr /\u003e\n\n1. **Download and install the Google API PHP Client.**\n\n The preferred method is using [Composer](//getcomposer.org/): \n\n composer require google/apiclient:^2.18.2 google/apiclient-services:=0.396.0\n\n Once installed, be sure to include the autoloader: \n\n require_once '/path/to/your-project/vendor/autoload.php';\n\n2. **Create a Google_Client object.**\n\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. See our\n [Authorize\n Requests](/display-video/api/guides/how-tos/authorizing#user_permissions) guide\n for more details on Display \\& Video 360 user permissions.\n\n // Set up the client.\n $client-\u003esetApplicationName('DV360 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 $service = new Google_Service_DisplayVideo($client);\n\n5. **Perform an operation.**\n\n // Configure params for the advertisers.list request.\n $optParams = array('pageSize' =\u003e 10, 'partnerId' =\u003e \u003cvar translate=\"no\"\u003epartner-id\u003c/var\u003e);\n\n // Execute the request.\n $result = $service-\u003eadvertisers-\u003elistAdvertisers($optParams);\n\n // Print the retrieved advertisers.\n if (!empty($result-\u003egetAdvertisers())) {\n print('\u003cpre\u003e');\n foreach ($result-\u003egetAdvertisers() as $advertiser) {\n printf('\u003cp\u003eID: %s, Display Name: %s\u003c/p\u003e', $advertiser-\u003eadvertiserId, $advertiser-\u003edisplayName);\n }\n print('\u003c/pre\u003e');\n } else {\n print '\u003cp\u003eNo advertisers found.\u003c/p\u003e';\n }"]]