Tag Archives: dfp_api

Announcing v201611 release of the DFP API

Today we’re pleased to announce the v201611 release of the DFP API. This release contains the addition of MobileApplicationService, which allows you to claim apps from various app stores to use for targeting in your network. For a full list of API changes in v201611, see the release notes.

With each new release comes a new deprecation. If you're using v201602 or earlier, it's time to look into upgrading. Also remember that a double sunset happened at the end of November 2016 - both v201508 and v201511 have been sunset.

As always, if you have any questions, feel free to drop us a line on the DFP API forums or the Ads Developer Google+ page.

How to properly refresh your OAuth2 access token in DFP API

In July we announced that starting in August 2016, all versions of the DFP API would return HTTP 401 errors instead of SOAP AUTHENTICATION_FAILED errors. We have learned that some developers have been relying on catching an AUTHENTICATION_FAILED error to know when to refresh an access token. This is not the recommended way to determine when your access token needs refreshing and is not supported.

The change described above will break code that relies on catching an AUTHENTICATION_FAILED error. We have temporarily rolled back the change to give developers who haven’t migrated more time to update their code and will roll this change out again on November 30, 2016 and ask that you update your code before then.

Note: If you’re taking advantage of our client libraries, no change is required; our client libraries handle refreshing an access token with our recommended approach.

Instead of relying on an AUTHENTICATION_FAILED error, the recommended way is to calculate how soon the access token is going to expire before making an API call, and refresh it if it’s about to expire soon.

  • Whenever you obtain a new access token, calculate the token’s expiration time by adding the expires_in time returned with the access token to the current time.
    • For example, if you received an access token on Oct 21, 16:05 EDT and the access token lasts for 3600 seconds, the token would expire on Oct 21, 17:05 EDT.
  • Then, before every DFP API call, check when the access token will expire before using it: if it is going to expire within a certain time window (say, in the next 60 seconds), you should refresh it before making the API call.
    • To calculate this, subtract the current time from the token’s expiration time that you calculated above.
You can see an example of how this is done in our Java client library and use it as a reference to help you implement the above.

As always, if you have any questions, feel free to drop us a line on the DFP API forums or the Ads Developer Google+ page.

Demystifying OAuth2 in DFP

Authentication with the DFP API is probably something you had to set up once and then never thought about again. Well, that may be true until there's a scope change, or your credentials suddenly stop working, or the developer who created the credentials leaves to open their own yoga studio in the Andes.

Understanding some of the finer details of DFP's OAuth2 flows can come in handy when the unexpected happens.

Access tokens

When using the DFP API, you can authenticate on behalf of a user in your network or as an application. For the DFP API we call these two choices Web Application flow and Service account flow (server-to-server), respectively. Each choice has a different set-up, but both are used to generate access tokens.

All DFP API requests are authenticated using access tokens. You can think of these as short-lived (about one hour) passwords. When making a request, you include the access token in the HTTP header:


Authorization: Bearer ACCESS_TOKEN

Every access token is tied to a specific user and one or more API scopes. The scopes control which Google APIs the access token is valid for. The scope for DFP is:


https://www.googleapis.com/auth/dfp

Access Control

Because every access token is associated with a user, the DFP API enforces the same exact access controls as the DFP UI. This means that all the teams, roles, and permissions that restrict the user are in effect.

When authenticating as a dedicated API user like a service account, make sure that user is configured with your desired teams and role in DFP. There's no requirement that API users have administrator access.

Troubleshooting

If you ever need to verify the scope or who the access token was issued to, you can easily do so using the OAuth2 API explorer. Enter the access token you're using, and the API will provide a JSON response with the details:

POST https://www.googleapis.com/oauth2/v2/tokeninfo?access_token=MY_ACCESS_TOKEN
{
"issued_to": "1234567890-aabbccddgh123.apps.googleusercontent.com",
"audience": "1234567890-aabbccddgh123.apps.googleusercontent.com",
"scope": "https://www.googleapis.com/auth/dfp",
"expires_in": 3496,
"access_type": "offline"
}

Refresh Tokens

Although we now recommend using service accounts for server-to-server flow, many integrations still use an installed application flow. This flow uses a refresh token to generate access tokens.

If your refresh token stops working, there are a few possible causes:

  • The user you're authenticating as no longer has access to the DFP network.
  • Too many refresh tokens were generated for the OAuth2 client.
  • The user you're authenticating as has revoked access for your application.

The simplest solution to all of these is to create a new client and generate a new refresh token for a current DFP user. Remember that the refresh token is tied to the account that authorizes the application, and not the user who created the OAuth2 client. When accepting the OAuth2 authorization prompt, verify that the user in the top right corner that is logged in is correct:

If OAuth2 still gives you a headache, we're happy to troubleshoot with you. Just reach out to us on our developer forum.

Sunset of DFP API v201508 and v201511

On Wednesday, November 30, 2016, in accordance with the deprecation schedule, v201508 and v201511 of the DFP API will be sunset. At that time, any requests made to these versions will return errors.

If you're still using these versions, now's the time to upgrade to the latest release and take advantage of new features like HTML5 creatives, programmatic support, and retrieving saved report queries. To do so, check the release notes to identify any breaking changes, grab the latest version of your client library, and update your code.

Significant changes include:

This is not an exhaustive list, so as always, don't hesitate to reach out to us with any questions. To be notified of future deprecations and sunsets, join the DFP API Sunset Announcements group and adjust your notification settings.

Setting up your DFP integration for success

It’s common to have multiple applications access your DFP network(s) when integrating with DFP. How you keep track of these applications and their authentication credentials can be just as important as writing code, particularly if you work with many other developers, or on more than one application. You want to avoid scenarios where you don’t know who or what is accessing your network, or where you can’t determine who owns the Google API Console project from which a set of OAuth2 credentials were generated. Here are some best practices to help mitigate this.

Managing your DFP credentials

It’s important to ensure that the right members of your team have access to the Google API Console project that generates your OAuth2 credentials. You can easily add multiple collaborators to an API Console project. This will help you track who’s integrating with DFP in a central location, rather than having each developer create their own API Console project.

Similarly, when choosing a Google account for DFP API authentication, you may want to consider an OAuth2 service account. That way, all members of an API Console project can easily access this account’s credentials through the console. This is much better than using an arbitrary individual’s account for authentication in case that person leaves your team, or has their account disabled.

Choose a strong application name

Defining an application name is required when making calls to the DFP API. However, we’ve seen a lot of not so useful application names, such as:
  • My DFP integration
  • abcxyz
  • Hello world!

This is particularly troublesome during sunsets when we send out emails identifying which application names are making calls to your network(s) using a deprecated API version. It’s difficult to track down what an application is doing, or who owns it, when it’s named something like "abcxyz". Here are some examples of better application names:

  • Monthly report download job
  • Weekly forecast script
  • Line item viewer

As always, if you have any questions, feel free to drop us a line on the DFP API forums or the Ads Developer Google+ page.

Google Ads API .NET client library runtime update

Beginning in November 2016, all new releases of the Google Ads API .NET client library will target .NET Framework 4.5.2+. Currently released client library versions will not be affected.

Why are runtime requirements changing?

On January 12th, 2016, Microsoft ended support for .NET Framework versions 4, 4.5, and 4.5.1. To ensure the continued security and stability of our client library, we will also stop supporting these legacy framework versions.

Additionally, increasing the runtime requirement allows us to make use of new framework functionality, to further improve and modernize the library.

How can you prepare?

If your application currently targets .NET Framework 4.5.2+, then no action is required. Users of .NET Framework versions <= 4.5.1 will need to upgrade to 4.5.2 in advance of the November 2016 release. Users on non-Windows platforms should similarly ensure that their version of Mono supports the .NET Framework 4.5.2 target.

If you have any questions or concerns, feel free to open an issue on the client library's issue tracker.

Announcing v201608 of the DFP API

If you’re in the Northern Hemisphere like I am, then you’re probably also experiencing the sweltering heatwave we’re enjoying this summer. You know what’s a great way to beat the heat? Stay inside and upgrade your DFP API version to the other hotness: v201608. If the prospect of air-conditioning isn’t enough to draw you away from the allure of melting outside, consider the following additional enhancements!

Programmatic & Sales Manager

One of the biggest features we’re adding to the DFP API is the support for programmatic guaranteed deals. This allows you to perform the end-to-end work of defining your inventory, negotiating with buyers, and trafficking to DFP all using the same great API you know and love (ours). To see how to create and use programmatic objects, see our API guide.

In addition to programmatic guaranteed, we’ve further enhanced the ProposalLineItem object by now providing information on whether the pricing model is Gross or Net via the ProposalLineItem.rateCardPricingModel field.

Trafficking

On the trafficking front, we’ve added the ability to delineate whether or not a creative isSafeFrameCompatible for applicable creative types such as CustomCreative. We’ve also added viewability tracking event types which can now be found on the ConversionEvent object. And finally, the one you’ve all been waiting for - there’s now support for the popular Html5Creative type.

Reporting

It’s not December, but it sure feels like the holiday season. If you’ve ever wanted to run a query you had saved in the UI, the ReportService has got your back. We’ve added ReportService.getSavedQueriesByStatement, which allows you to retrieve reports you’ve created in the UI. You can then run these using ReportService.runReportJob.

Of course, since this is an action-packed release, we can’t possibly list out everything we’ve changed in a blog post, so take a peek at the full release notes.

As a reminder, with each new release comes a new deprecation (this one’s special, it’s a double deprecation!). If you're using v201511 or earlier, it's time to look into upgrading to v201608. If you have any questions about upgrading, let us know on the developer forum.

Announcing the New DFP Playground

Today we’re pleased to announce the new and revamped DFP Playground. Like the previous Playground, you can test PQL statements and examine JSON equivalents of the objects you retrieve from the DFP API. In the new DFP Playground, you can easily switch between services using a tab interface, and you can even view documentation for a particular service with a simple click of a button.

The new DFP Playground's tab-based interface is cleaner and less crowded.

Clicking a result produces a dropdown with the object’s JSON representation.

Checking out the GitHub project

The DFP Playground is available on GitHub. Reading the code should give you a good idea of best practices for interacting with the DFP API via the Google Ads Python client library in a web application environment. The process to set up your own instance of the DFP Playground and deploy it to AppEngine is documented in the README.

Feel free to post any bug reports or feature requests in the issues section. If you have any questions regarding the DFP API, please reach out to us on our forum.

Sunset of the v201505 DFP API

On Wednesday, August 31, 2016, in accordance with the deprecation schedule, v201505 of the DFP API will be sunset. At that time, any requests made to v201505 will return errors.

If you're still using v201505, now's the time to upgrade to the latest release and take advantage of new features like workflow progress for Sales Manager. To do so, check the release notes to identify any breaking changes, grab the latest version of your client library and update your code.

Significant changes include:

This is not an exhaustive list, so as always, don't hesitate to reach out to us with any questions. To be notified of future deprecations and sunsets, join the DFP API Sunset Announcements group and adjust your notification settings.

Changes to DFP API authentication errors

In the past, we’ve thrown AUTHENTICATION_FAILED errors as API exceptions whenever an OAuth2 access token was invalid, expired, or missing. Starting on the release date of v201608, the DFP API will reject these requests as HTTP 401 errors (unauthorized access) instead of as API exceptions for all versions.

If you really break it down, this is a win-win for everyone involved. You don’t waste application quota on authentication requests that are already going to fail, and we can focus on doing what we do best, responding to valid API requests.

What does this mean for you? That’s a bit trickier. If you’re catching the old authentication errors raised by our client libraries, then you’re going to want to shift your integration to catching HTTP errors instead. Since our client libraries are implemented with language-specific practices in mind, you’d be looking for these new occurrences to show up as either errors raised by the underlying HTTP or SOAP libraries or wrapped HTTP errors in the libraries themselves. These failures are generally deterministic and require user action - either to generate a new refresh token, to add a new API user, or to create a valid client - so this is mostly a shift in where to catch the exception rather than wrapping with retry logic.

As usual, if you have any questions or just want to talk about API things, let us know on the developer forum.