Od 8 września 2025 r. każdy nowy element zamówienia będzie musiał deklarować, czy będzie wyświetlać reklamy polityczne w Unii Europejskiej (UE). Przesyłanie plików SDF i wywoływanie interfejsu Display & Video 360 API bez deklaracji zakończy się niepowodzeniem. Więcej informacji o tym, jak zaktualizować integrację, aby złożyć to oświadczenie, znajdziesz na naszej stronie dotyczącej wycofania.
Zadbaj o dobrą organizację dzięki kolekcji Zapisuj i kategoryzuj treści zgodnie ze swoimi preferencjami.
Po utworzeniu danych logowania OAuth 2.0 i zainstalowaniu biblioteki klienta możesz zacząć korzystać z interfejsu Display & Video 360 API. Aby dowiedzieć się, jak autoryzować i konfigurować klienta oraz wysyłać pierwsze prośby, wykonaj podane niżej czynności.
Wczytaj plik z tajnymi kluczami klienta i wygeneruj dane uwierzytelniające.
Gdy wykonujesz ten krok po raz pierwszy, w przeglądarce pojawi się prośba o autoryzację. Zanim zaakceptujesz, upewnij się, że logujesz się na konto Google, które ma dostęp do Display & Video 360. Aplikacja będzie mieć uprawnienia do uzyskiwania dostępu do danych w imieniu konta, na którym jest obecnie zalogowany użytkownik. Więcej informacji o uprawnieniach użytkowników Display & Video 360 znajdziesz w poradniku AuthorizeRequests.
// 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");
Utwórz autoryzowanego klienta interfejsu API.
// Create authorized API client.DisplayVideoservice=newDisplayVideo.Builder(credential.getTransport(),credential.getJsonFactory(),credential).setApplicationName("displayvideo-java-installed-app-sample").build();
Wykonaj operację.
// 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.");}
Wczytaj plik z tajnymi kluczami klienta i wygeneruj dane uwierzytelniające.
Gdy wykonujesz ten krok po raz pierwszy, w przeglądarce pojawi się prośba o autoryzację. Zanim zaakceptujesz, upewnij się, że logujesz się na konto Google, które ma dostęp do Display & Video 360. Aplikacja będzie mieć uprawnienia do uzyskiwania dostępu do danych w imieniu konta, na którym jest obecnie zalogowany użytkownik. Więcej informacji o uprawnieniach użytkowników Display & Video 360 znajdziesz w poradniku AuthorizeRequests.
# 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()
Utwórz autoryzowanego klienta interfejsu 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)
W tym przykładzie zakładamy, że używasz PHP z wbudowanym serwerem WWW i masz skonfigurowane dane logowania, które przekierowują do odpowiedniej strony internetowej. Ten kod w pliku index.php można uruchomić za pomocą tego polecenia i danych logowania skonfigurowanych tak, aby po uwierzytelnieniu nastąpiło przekierowanie do http://localhost:8000:
php-Slocalhost:8000-t./
Pobierz i zainstaluj klienta PHP interfejsu Google API.
Skonfiguruj klienta, w razie potrzeby przekieruj do adresu URL uwierzytelniania i pobierz token dostępu.
Gdy wykonujesz ten krok po raz pierwszy, w przeglądarce pojawi się prośba o autoryzację. Zanim zaakceptujesz, upewnij się, że logujesz się na konto Google, które ma dostęp do Display & Video 360. Aplikacja będzie mieć uprawnienia do uzyskiwania dostępu do danych w imieniu konta, na którym jest obecnie zalogowany użytkownik. Więcej informacji o uprawnieniach użytkowników Display & Video 360 znajdziesz w poradniku AuthorizeRequests.
// 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);
Utwórz klienta dla usługi interfejsu Display & Video 360 API.
$service = new Google_Service_DisplayVideo($client);
Wykonaj operację.
// 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>';}
[[["Łatwo zrozumieć","easyToUnderstand","thumb-up"],["Rozwiązało to mój problem","solvedMyProblem","thumb-up"],["Inne","otherUp","thumb-up"]],[["Brak potrzebnych mi informacji","missingTheInformationINeed","thumb-down"],["Zbyt skomplikowane / zbyt wiele czynności do wykonania","tooComplicatedTooManySteps","thumb-down"],["Nieaktualne treści","outOfDate","thumb-down"],["Problem z tłumaczeniem","translationIssue","thumb-down"],["Problem z przykładami/kodem","samplesCodeIssue","thumb-down"],["Inne","otherDown","thumb-down"]],["Ostatnia aktualizacja: 2025-07-25 UTC."],[[["\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,["With [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\nJava\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\nPython\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\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 -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 }"]]