The DCM/DFA Reporting and Trafficking API v2.7 is deprecated and will be sunset on December 7th, 2017. All users must migrate to a newer API version by that date.

Get started

The DCM/DFA Reporting and Trafficking API provides programmatic access to information from your DoubleClick Campaign Manager (DCM) account. It's used to manage and create campaigns and reports, just as you would through the DCM and Report Builder web services.

This guide describes how to get started with the DCM/DFA Reporting and Trafficking API.

Prerequisites

Before using the DCM/DFA Reporting and Trafficking API, there are a few prerequisite steps you'll need to satisfy:

  1. You must have a DCM account. See Advertisers/Agencies for signup information.
  2. Your DCM account must be enabled for API Access. Most accounts have this enabled by default; if you're not sure, contact your DoubleClick representative or the DCM support team for assistance.
  3. You must have a user profile with access to this account. Have your DCM account administrator create a user profile associated with this account.
  4. Check user profile permissions in the DCM UI. These control what the user profile can access from the API. There are no separate API permissions.

Create a project

To get started using the DCM/DFA Reporting and Trafficking API, you need to first create or select a project in the Google API Console and enable the API. Using this link guides you through the process and activates the DCM/DFA Reporting and Trafficking API automatically.

Generate credentials

All requests you make to the DCM/DFA Reporting and Trafficking API must be authorized. For a brief overview of authorization, read about how to authorize and identify your application to Google.

The following instructions guide you through the process of creating an OAuth 2.0 client ID to use with the installed application flow. For instructions on generating credentials for use with the service account flow, refer to the Service Accounts guide.

  1. Follow the steps to configure a Google API Console project.
  2. Open the Credentials page in the API Console.
  3. Click Create credentials > OAuth client ID.
  4. Select Other when prompted to select an application type and enter any additional required information.
    • If this is your first time creating a client ID, besides being able to select your application type, you can configure your consent screen by clicking the Configure consent screen button. You will not get a prompt to configure your consent screen again after you do it the first time, although this information can be updated at any time.
  5. Click Create.

When finished, you'll be presented with an OAuth 2.0 client ID and client secret, which you can download in JSON format and save for later use.

Install a client library

The DCM/DFA Reporting and Trafficking API is built on HTTP and JSON, so any standard HTTP client can send requests to it and parse the responses.

However, the Google API client libraries provide better language integration, improved security, and support for making authorized requests. The client libraries are available in a number of programming languages; by using them you can avoid the need to manually set up HTTP requests and parse the responses.

To get started, select the programming language that you're using for development.

C#

Install the latest DCM/DFA Reporting and Trafficking API client library for .NET. Using NuGet to manage your installation is recommended.

Open the NuGet Package Manager Console and run the following command:

Install-Package Google.Apis.Dfareporting.v3_0

Learn More

Java

Install the latest DCM/DFA Reporting and Trafficking API client library for Java. Using Maven to manage your installation is recommended.

Add the following dependency to your pom.xml file:

    <dependency>
      <groupId>com.google.apis</groupId>
      <artifactId>google-api-services-dfareporting</artifactId>
      <version>v3.0-rev1-1.23.0</version>
      <exclusions>
        <exclusion>
          <groupId>com.google.guava</groupId>
          <artifactId>guava-jdk5</artifactId>
        </exclusion>
      </exclusions>
    </dependency>

Learn More

PHP

Install the latest DCM/DFA Reporting and Trafficking API client library for PHP. Using Composer to manage your installation is recommended.

Open a terminal and run the following command:

composer require google/apiclient

If you've already installed the library and just want to update to the latest version:

composer update google/apiclient

Depending on your system, you may need to prepend these commands with sudo.

Learn More

Python

Install the latest DCM/DFA Reporting and Trafficking API client library for Python. Using pip to manage your installation is recommended.

Open a terminal and run the following command:

pip install --upgrade google-api-python-client

Depending on your system, you may need to prepend these commands with sudo.

Learn More

Ruby

Install the latest DCM/DFA Reporting and Trafficking API client library for Ruby. Using RubyGems to manage your installation is recommended.

Open a terminal and run the following command:

gem install google-api-client

If you've already installed the library and just want to update to the latest version:

gem update -y google-api-client

Depending on your system, you may need to prepend these commands with sudo.

Learn More

More supported languages can be found on the Client Libraries page.

Make a request

With OAuth 2.0 credentials created and a client library installed, you're ready to start using the DCM/DFA Reporting and Trafficking API. Learn how to authorize, configure your client, and make your first request by following the quickstart below.

C#

  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 DCM. Your application will be authorized to access data on behalf of whichever account is currently logged in.

    // Load client secrets from the specified JSON file.
    GoogleClientSecrets clientSecrets;
    using(Stream json = new FileStream(pathToJsonFile, FileMode.Open, FileAccess.Read)) {
      clientSecrets = GoogleClientSecrets.Load(json);
    }
    
    // Create an asynchronous authorization task.
    //
    // Note: providing a data 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. The "user" value is used to
    // identify a specific set of credentials within the data store. You may provide different
    // values here to persist credentials for multiple users to the same data store.
    Task<UserCredential> authorizationTask = GoogleWebAuthorizationBroker.AuthorizeAsync(
        clientSecrets.Secrets,
        OAuthScopes,
        "user",
        CancellationToken.None,
        dataStore);
    
    // Authorize and persist credentials to the data store.
    UserCredential credential = authorizationTask.Result;
    

  2. Create an authorized Dfareporting client.

    // Create a Dfareporting service object.
    //
    // Note: application name should be replaced with a value that identifies your application.
    service = new DfareportingService(
        new BaseClientService.Initializer {
          HttpClientInitializer = credential,
          ApplicationName = "C# installed app sample"
        }
    );
    

  3. Perform an operation.

    // Retrieve and print all user profiles for the current authorized user.
    UserProfileList profiles = service.UserProfiles.List().Execute();
    
    foreach (UserProfile profile in profiles.Items) {
      Console.WriteLine("Found user profile with ID {0} and name \"{1}\".",
          profile.ProfileId, profile.UserName);
    }
    

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 DCM. 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 Dfareporting client.

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

  3. Perform an operation.

    // Retrieve and print all user profiles for the current authorized user.
    UserProfileList profiles = reporting.userProfiles().list().execute();
    for (int i = 0; i < profiles.getItems().size(); i++) {
      System.out.printf("%d) %s%n", i + 1, profiles.getItems().get(i).getUserName());
    }
    

PHP

  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 DCM. Your application will be authorized to access data on behalf of whichever account is currently logged in.

    // Create a Google_Client instance.
    //
    // Note: application name should be replaced with a value that identifies
    // your application. Suggested format is "MyCompany-ProductName".
    $client = new Google_Client();
    $client->setAccessType('offline');
    $client->setApplicationName('PHP installed app sample');
    $client->setRedirectUri(self::OAUTH_REDIRECT_URI);
    $client->setScopes(self::$OAUTH_SCOPES);
    
    // Load the client secrets file.
    $client->setAuthConfig($pathToJsonFile);
    
    // Try to load cached credentials from the token store. Using a token 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.
    if (file_exists($tokenStore) && filesize($tokenStore) > 0) {
      $client->setAccessToken(file_get_contents($tokenStore));
    } else {
      // If no cached credentials were found, authorize and persist
      // credentials to the token store.
      print 'Open this URL in your browser and authorize the application.';
      printf("\n\n%s\n\n", $client->createAuthUrl());
      print 'Enter the authorization code: ';
      $code = trim(fgets(STDIN));
      $client->authenticate($code);
    
      file_put_contents($tokenStore, json_encode($client->getAccessToken()));
    }
    

  2. Create an authorized Dfareporting client.

    // Create a Dfareporting service object.
    $service = new Google_Service_Dfareporting($client);
    

  3. Perform an operation.

    // Retrieve and print all user profiles for the current authorized user.
    $result = $service->userProfiles->listUserProfiles();
    foreach ($result['items'] as $userProfile) {
      printf(
          "User profile \"%s\" (ID: %d) found for account %d.\n",
          $userProfile->getUserName(),
          $userProfile->getProfileId(),
          $userProfile->getAccountId()
      );
    }
    

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 DCM. 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(flags.json_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, flags)
    
    # Use the credentials to authorize an httplib2.Http instance.
    http = credentials.authorize(httplib2.Http())
    

  2. Create an authorized Dfareporting client.

    # Construct a service object via the discovery service.
    service = discovery.build('dfareporting', 'v3.0', http=http)
    

  3. Perform an operation.

    # Construct the request.
    request = service.userProfiles().list()
    
    # Execute request and print response.
    response = request.execute()
    
    for profile in response['items']:
      print('Found user profile with ID %s and user name "%s".' %
            (profile['profileId'], profile['userName']))
    

Ruby

  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 DCM. Your application will be authorized to access data on behalf of whichever account is currently logged in.

    # Load client ID from the specified file.
    client_id = Google::Auth::ClientId.from_file(path_to_json_file)
    
    # Set up the user authorizer.
    #
    # Note: providing a token 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.
    authorizer = Google::Auth::UserAuthorizer.new(
        client_id, [API_NAMESPACE::AUTH_DFAREPORTING], token_store)
    
    # Authorize and persist credentials to the data store.
    #
    # Note: the 'user' value below is used to identify a specific set of
    # credentials in the token store. You may provide different values here to
    # persist credentials for multiple users to the same token store.
    authorization = authorizer.get_credentials('user')
    if authorization.nil?
      puts "Open this URL in your browser and authorize the application."
      puts
      puts authorizer.get_authorization_url(base_url: OAUTH_REDIRECT_URI)
      puts
      puts "Enter the authorization code:"
      code = STDIN.gets.chomp
      authorization = authorizer.get_and_store_credentials_from_code(
          base_url: OAUTH_REDIRECT_URI, code: code, user_id: 'user')
    end
    

  2. Create an authorized Dfareporting client.

    # Create a Dfareporting service object.
    #
    # Note: application name should be replaced with a value that identifies
    # your application. Suggested format is "MyCompany-ProductName".
    service = API_NAMESPACE::DfareportingService.new
    service.authorization = authorization
    service.client_options.application_name = "Ruby installed app sample"
    service.client_options.application_version = '1.0.0'
    

  3. Perform an operation.

    // Retrieve and print all user profiles for the current authorized user.
    UserProfileList profiles = service.UserProfiles.List().Execute();
    
    foreach (UserProfile profile in profiles.Items) {
      Console.WriteLine("Found user profile with ID {0} and name \"{1}\".",
          profile.ProfileId, profile.UserName);
    }
    

Learn more

Visit the API Reference to learn about all of the services the API has to offer. Every method detail page has an embedded API Explorer you can use to make test requests directly from your browser.

Review our other guides which cover advanced topics and provide end-to-end examples for common tasks.

When you're ready to start writing code, feel free to explore our extensive collection of code samples, which may be modified and extended to fit your needs.

Send feedback about...

DoubleClick Campaign Manager
DoubleClick Campaign Manager