Until now, the DFP API only supported the OAuth 2.0 native/installed application flow. The OAuth 2.0 service account flow was only supported it you had a Google Apps for Business Account. Today, we’re unveiling the new OAuth 2.0 service account flow for DFP. This authorization flow has been simplified to no longer require a Google Apps domain. We’ve also updated the DFP web UI to allow service accounts to be added to be a DFP network.
Why should I use service accounts?
Service accounts allow access to Google APIs without the need for user interaction by authenticating solely with server-to-server interactions. Other OAuth 2.0 flows require user interaction or having an application cache a refresh token.
How do I use service accounts?
- Generate a service account key from the Google Developers Console.
- Add the service account to your DFP network by going to the Admin tab and clicking the Add a service account user button.
- Fill in the form with your Name, Email, Teams (if applicable), and Role. Then, click Save.
- View existing service account users by going to the Users tab and then clicking the Service Account filter.
With the *.p12 key generated from the Google Developers Console and the service account added to the DFP network, you can now generate an OAuth 2.0 token. For example, using the Java client library:
GoogleCredential credential = new GoogleCredential.Builder() .setTransport(new NetHttpTransport()) .setJsonFactory(new GsonFactory()) .setServiceAccountId("****@developer.gserviceaccount.com") .setServiceAccountScopes("https://www.googleapis.com/auth/dfp") .setServiceAccountPrivateKeyFromP12File(new File("/path/to/key.p12")) .build();
For more information, see our updated guide on using service accounts with DFP.