This is a collection of samples written in PHP which provide a starting place for your experimentation into Bid Manager API v2.
- PHP 7.2+
- Composer
From the example directory, run composer install to install all dependencies.
This API uses OAuth 2.0. Learn more about Google APIs and OAuth 2.0 here: https://developers.google.com/accounts/docs/OAuth2
If you've already set up Application Default
Credentials
at the environmental variable GOOGLE_APPLICATION_CREDENTIALS, the sample
suite will automatically use those credentials for authentication.*
Follow these steps to enable the API for your Google Cloud Platform project and generate the necessary credentials:
- Visit Google Developers Console to select or create your project.
- From the API Manager → Google APIs screen, activate access to "DoubleClick Bid Manager API".
- Click on "Credentials" in the left navigation menu
- Click the button labeled "Create credentials" and select "OAuth Client ID"
- Select "Web Application" as the "Application type", set the following
values, then "Create":
- Authorized Javascript Origins:
http://localhost:8000 - Authorized Redirect URIs:
http://localhost:8000/index.php
- Authorized Javascript Origins:
- From the Credentials page, click the "Download OAuth Client" icon under "Actions" next to the client ID you just created and click "Download JSON".
- Save the downloaded file as
client_secrets.jsonin your home directory.
These samples support authentication using a service account key. To run samples using a service account, follow these steps after completing steps 1 and 2 from the section above:
- Click on "Credentials" in the left navigation menu.
- Click the button labeled "Create credentials" and select "Service Account".
- Provide a "Service account name", "Service account ID", and "Service account description", then "Create and Continue".
- From the Credentials page, click the new service account email.
- Navigate to the "Keys" tab, click "Add Key", and create a new JSON key, which will download automatically.
- Save the downloaded file as
service_account_key.jsonin your home directory. - When opening the sample webpage, include the query parameter
service_account=trueto authenticate using the service account key.
If you are using a service account for authentication, create and download a
JSON service account
key,
save the file as service_account_key.json in your examples, and include the
query parameter service_account=true when opening the sample.
Always ensure that your
client_secrets.jsonandservice_account_key.jsonfiles are not publicly accessible. These files have credential information which could allow unauthorized access to your Display & Video 360 data.
Once you've checked out the code and installed dependencies using Composer, you can run the examples locally:
- Via the command line, execute the following command in this directory:
php -S localhost:8000 -t ./
- Open the sample (http://localhost:8000/index.php) in your browser.
- Click
Connect Meto start an authentication flow, redirect back to your server, and then run the samples against your Display & Video 360 account.
Note: To use a service account for authentication, open the sample using
the following url: http://localhost:8000/index.php?service_account=true