Starting September 8, 2025, every new line item will need to declare whether or not they will serve Eurpoean Union (EU) political ads. Display & Video 360 API and SDF uploads that don't provide declarations will fail. See our deprecations page for more details on how to update your integration to make this declaration.
Stay organized with collections
Save and categorize content based on your preferences.
With OAuth 2.0 credentials created and a client library
installed, you're ready to start using the Display & Video 360 API.
Learn how to authorize, configure your client, and make your first request by
following the quickstart below.
Load the client secrets file and generate authorization credentials.
The first time you perform this step, you are asked to accept an authorization
prompt in your browser. Before accepting, make sure you're signed in with a
Google Account that has access to Display & Video 360. Your app will be authorized
to access data on behalf of whichever account is currently signed in. See our
Authorize
Requests guide
for more details on Display & Video 360 user permissions.
// 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");
Create an authorized API client.
// Create authorized API client.DisplayVideoservice=newDisplayVideo.Builder(credential.getTransport(),credential.getJsonFactory(),credential).setApplicationName("displayvideo-java-installed-app-sample").build();
Perform an operation.
// 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.");}
Load the client secrets file and generate authorization credentials.
The first time you perform this step, you are asked to accept an authorization
prompt in your browser. Before accepting, make sure you're signed in with a
Google Account that has access to Display & Video 360. Your app will be authorized
to access data on behalf of whichever account is currently signed in. See our
Authorize
Requests guide
for more details on Display & Video 360 user permissions.
# 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()
Create an authorized API client.
# 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)
This sample assumes that you are running the PHP with a built-in web server and
have configured your credentials to redirect to the relevant web page. For
example, this code, in an index.php file, can be run using the following
command and credentials configured to redirect to http://localhost:8000 after
authentication:
Set up the client, redirect to authentication URL if needed, and retrieve an access token.
The first time you perform this step, you are asked to accept an authorization
prompt in your browser. Before accepting, make sure you're signed in with a
Google Account that has access to Display & Video 360. Your app will be authorized
to access data on behalf of whichever account is currently signed in. See our
Authorize
Requests guide
for more details on Display & Video 360 user permissions.
// 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);
Construct a client for the Display & Video 360 API service.
$service = new Google_Service_DisplayVideo($client);
Perform an operation.
// 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>';}
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-04-09 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,["# 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 }"]]