Configure your client

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.

Java

  1. Load the client secrets file and generate authorization credentials.

    The first time you perform this step you'll be asked to accept an authorization prompt in your browser. Before accepting, make sure you're logged in with a Google Account that has access to Display & Video 360. Your application will be authorized to access data on behalf of whichever account is currently logged in.

      // Load the client secrets JSON file.
      GoogleClientSecrets clientSecrets =
        GoogleClientSecrets.load(
          jsonFactory, Files.newBufferedReader(Paths.get(pathToClientSecretsFile), UTF_8));
    
      // Set up the authorization code flow.
      //
      // Note: providing a DataStoreFactory allows auth credentials to be cached, so they survive
      // multiple runs of the program. This avoids prompting the user for authorization every time the
      // access token expires, by remembering the refresh token.
      GoogleAuthorizationCodeFlow flow =
        new GoogleAuthorizationCodeFlow.Builder(
          httpTransport, jsonFactory, clientSecrets, OAUTH_SCOPES)
          .setDataStoreFactory(dataStoreFactory)
          .build();
    
      // Authorize and persist credentials to the data store.
      //
      // Note: the "user" value below is used to identify a specific set of credentials in the data
      // store. You may provide different values here to persist credentials for multiple users to
      // the same data store.
      Credential credential =
        new AuthorizationCodeInstalledApp(flow, new LocalServerReceiver()).authorize("user");
    
  2. Create an authorized API client.

      // Create a DisplayVideo client instance.
      //
      // Note: application name below should be replaced with a value that identifies your
      // application. Suggested format is "MyCompany-ProductName/Version.MinorVersion".
      DisplayVideo service =
        new DisplayVideo.Builder(credential.getTransport(), credential.getJsonFactory(), credential)
          .setApplicationName("displayvideo-java-installed-app-sample")
          .build();
    
  3. Perform an operation.

      // Retrieve and print the first ten advertisers under a partner.
      ListAdvertisersResponse advertisersResponse = service.advertisers().list().setPartnerId(partner-id).setPageSize(10).execute();
      for (int i = 0; i < advertisersResponse.getAdvertisers().size(); i++) {
        System.out.printf("%d) %s%n", i + 1, advertisersResponse.getAdvertisers().get(i).getDisplayName());
      }
    

Python

  1. Load the client secrets file and generate authorization credentials.

    The first time you perform this step you'll be asked to accept an authorization prompt in your browser. Before accepting, make sure you're logged in with a Google Account that has access to Display & Video 360. Your application will be authorized to access data on behalf of whichever account is currently logged in.

      # Set up a Flow object to be used if we need to authenticate.
      flow = client.flow_from_clientsecrets(
          path_to_client_secrets_file, scope=OAUTH_SCOPES)
    
      # Check whether credentials exist in the credential store. Using a credential
      # store allows auth credentials to be cached, so they survive multiple runs
      # of the application. This avoids prompting the user for authorization every
      # time the access token expires, by remembering the refresh token.
      storage = Storage(CREDENTIAL_STORE_FILE)
      credentials = storage.get()
    
      # If no credentials were found, go through the authorization process and
      # persist credentials to the credential store.
      if credentials is None or credentials.invalid:
        credentials = tools.run_flow(flow, storage)
    
      # Use the credentials to authorize an httplib2.Http instance.
      http = credentials.authorize(httplib2.Http())
    
  2. Create an authorized API client.

      # Construct a service object via the discovery service url.
      service = discovery.build('displayvideo', 'v1beta',
                              discoveryServiceUrl=discovery_url,
                              http=http)
    
  3. Perform an operation.

      # Construct the request to get the first 10 advertisers under a partner.
      request = service.advertisers().list(partnerId='partner-id', pageSize='10')
    
      # Execute request and print response.
      response = request.execute()
    
      for profile in response['advertisers']:
        print('Found advertiser with ID %s and display name "%s".' %
              (profile['advertiserId'], profile['displayName']))