Google DFP Client for Node.JS

1,561 views
Skip to first unread message

Roy Pereira

unread,
May 20, 2014, 9:13:07 PM5/20/14
to google-doubleclick...@googlegroups.com
We just made public a GitHub repo for a Node.JS DFP client at https://github.com/ShinyAds/node-google-dfp.

You can install is by running "npm install node-google-dfp".

This node.JS client leverages Google's 'googleapis' node.JS client for OAUTH and leverage's DFP's Soap schema heavily, so it should be future-proof.

Let us know what you think and please help making it better by contributing.





Aaron Siladi

unread,
Jun 13, 2014, 6:45:38 PM6/13/14
to google-doubleclick...@googlegroups.com
Looks great... thank you!!!  Just what I was looking for.

It doesn't work w/ v201405 - I see this in the release note:

"To align better with OAuth2 standards, starting in v201405 we have removed the OAuth2 SOAP object. This means that you can no longer pass OAuth2 authentication information through the SOAP header. Instead, you pass it in the HTTP header. All of our client libraries have already been updated to follow this process. If your integration is not using one of our client libraries, please be aware of this change when you upgrade to v201405. "

Any tips how I could update the code to follow this change?  I can work on it and submit a pull request to make it configurable how the OAuth2 authentication info gets passed. 


Andre de Souza

unread,
Jun 16, 2014, 4:26:34 PM6/16/14
to google-doubleclick...@googlegroups.com
Hi Aaron,

    Thanks for feedback. 

    I have only tested with v201405 and it does seem to work, but the OAuth part is incomplete in terms of going through the whole OAuth process -it assumes you have a refresh token. Any help is more than welcome! My sample code;

var DfpClass = require('./lib/Dfp');
var dfpUser = new DfpClass.User('YOUR NETWORK CODE', 'YOUR APP NAME');

dfpUser.setSettings({
  client_id: "YOUR CLIENT ID",
  client_secret: "YOUR CLIENT SECRET",
  refresh_token: "REFRESH TOKEN",
  redirect_url: "YOUR REDIRECT URL"
});


dfpUser.getService('InventoryService', function (inventoryService) {

  var args = new DfpClass.Statement('LIMIT 100');

  inventoryService.getAdUnitSizesByStatement(args, function (err, results) {
    if (err) {
      console.log(err.response.body);
      return;
    }
    console.log(results.rval);
  });

});


As I said, any input is welcome.

Thanks,
Andre 

Andre de Souza

unread,
Jun 17, 2014, 9:22:58 AM6/17/14
to google-doubleclick...@googlegroups.com
Hi Aaron... I see what you mean. Strangely, when I run my tests from office they work (maybe the bearer token has not expired from when this changed?), from home it is not connecting because of the missing authorization header.

Aaron Siladi

unread,
Jun 17, 2014, 6:34:17 PM6/17/14
to google-doubleclick...@googlegroups.com
Andre,

OK, glad you see same error :)

The v201405 API version was only released last week, so perhaps OAuth changes were not finalized until that time. 

I have not looked into yet, but should be possible to set the auth headers in 'request' package, instead of on soap client. 

I'll be away until 24th, I look forward to collaborate more once I return to office.

Thanks,
Aaron

René Simon

unread,
Oct 14, 2014, 3:15:01 AM10/14/14
to google-doubleclick...@googlegroups.com
Hello,

I'm new in this group.
I want to develop a Node Service which uses node-google-dfp.

My problem is that I do not know where to get the refresh_token and the redirect_url?

Second think is that I thought we have to use service accounts to access the dfp services.
So what should I put for client_id and client_secret?

Thanks a lot in advance.

Siladi, Aaron

unread,
Oct 14, 2014, 4:35:23 PM10/14/14
to rene.si...@gmail.com, google-doubleclick...@googlegroups.com

Rene

 

You need to create/register an app on the Google Cloud Console

 

Here are the basic instructions: https://developers.google.com/accounts/docs/OAuth2#basicsteps

 

Regarding role-based access, I don’t think that is available from API.  So your entire app will use same client_secret/client_key 

 

Hope this helps you out.

 

Thanks,

Aaron

--
You received this message because you are subscribed to a topic in the Google Groups "Google's DoubleClick for Publishers API Forum" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/google-doubleclick-for-publishers-api/3xwCg6UohMo/unsubscribe.
To unsubscribe from this group and all its topics, send an email to google-doubleclick-for-p...@googlegroups.com.
To post to this group, send email to google-doubleclick...@googlegroups.com.
Visit this group at http://groups.google.com/group/google-doubleclick-for-publishers-api.
For more options, visit https://groups.google.com/d/optout.

Vincent Tsao (DFP API Team)

unread,
Oct 14, 2014, 6:45:43 PM10/14/14
to google-doubleclick...@googlegroups.com, rene.si...@gmail.com
Hi Rene:

Since you're not using one of our official Google client libraries, you'll need to handle the OAuth2 dance yourself. Please see our authentication guide here:

And our service account guide here:

Thanks,
Vincent Tsao, DFP API Team

To unsubscribe from this group and all its topics, send an email to google-doubleclick-for-publishers-api+unsubscribe@googlegroups.com.
To post to this group, send email to google-doubleclick-for-publishers-api@googlegroups.com.

René Simon

unread,
Oct 15, 2014, 3:14:11 AM10/15/14
to google-doubleclick...@googlegroups.com, rene.si...@gmail.com
Thanks Aaron and Vincent. That helped a lot.

As most of the time answers lead to more questions :-)

On the pages Vincent posted I found a description how I have to build a request to get the refresh token etc.
To make this request I need a code, how to get it is also explained there.
But I should use the scope query param to make this request and to choose which scope I should look in the APIs description via the API Explorer.
The Problem is, that I do not find the DFP API in there.
So can you please tell me which are the possible scope values for the request to https://accounts.google.com/o/oauth2/auth?

And can I use the responded refresh token for node-google-dfp straight away or do I need to register the clientId first as DFP Service Account User. If the second one is true, how do I do that because I do not have a valid email adress for this client.

Thanks again

René

Vincent Tsao (DFP API Team)

unread,
Oct 15, 2014, 5:57:35 PM10/15/14
to google-doubleclick...@googlegroups.com, rene.si...@gmail.com
For the DFP API scope, please see this link:

For how to add a service account email to your network, the link I sent you will also show you how:

is this what you're asking? There's a special add service account button in the DFP UI that will not require email validation for adding a service account user.

Thanks,
Vincent Tsao, DFP API Team


René Simon

unread,
Oct 16, 2014, 2:54:27 AM10/16/14
to google-doubleclick...@googlegroups.com, rene.si...@gmail.com
Thanks again for the answers.
I have only a few hours every morning to work on this project and I love that I have a new answer and reach a new step every day.
Thanks a lot for that.

and got the "code".

When I then sent a POST request to https://accounts.google.com/o/oauth2/token wich looks like this:
POST /o/oauth2/token HTTP/1.1
Host: accounts.google.com
Content-Type: application/x-www-form-urlencoded

code=#code#&client_id=#clientId#&client_secret=#clientSecret#&redirect_uri=urn%3Aietf%3Awg%3Aoauth%3A2.0%3Aoob&grant_type=authorization_code

I always get this response:
{
    "error": "invalid_request",
    "error_description": "Required parameter is missing: grant_type"
}


Can you tell me what I'm doing wrong?

Vincent Tsao (DFP API Team)

unread,
Oct 16, 2014, 3:16:55 PM10/16/14
to google-doubleclick...@googlegroups.com, rene.si...@gmail.com
You need to pass in a grant_type, please see the documentation here:

Thanks,
Vincent Tsao, DFP API Team

Siladi, Aaron

unread,
Oct 16, 2014, 7:16:04 PM10/16/14
to dfpapi-advi...@google.com, google-doubleclick...@googlegroups.com, rene.si...@gmail.com

Rene

 

Looks like you passed a grant_type in your request, not sure why it failed. 

 

The following worked fine for me : 

 

curl --data "grant_type=authorization_code&client_id=REDACTED&client_secret=REDACTED&code=REDACTED" https://accounts.google.com/o/oauth2/token

 

Once you get this refresh token, you can continually refresh using that, by using the `googleapis` node.js module like so:

 

var OAuth2 = require('googleapis').auth.OAuth2;

var OAuthClient = new OAuth2(client_id, client_secret, redirect_url);

OAuthClient.credentials = { refresh_token: refresh_token };

 

OAuthClient.refreshAccessToken(function(token){

  // token arg passed to callback will have properties ‘access_token’, ‘token_type’, ‘expires_in’, and ‘refresh_token’

});

 

Hope this helps you out!!!

 

Thanks,

Aaron

 

 

From: google-doubleclick...@googlegroups.com [mailto:google-doubleclick...@googlegroups.com] On Behalf Of Vincent Tsao (DFP API Team)
Sent: Thursday, October 16, 2014 12:17 PM
To: google-doubleclick...@googlegroups.com
Cc: rene.si...@gmail.com
Subject: Re: Google DFP Client for Node.JS

 

You need to pass in a grant_type, please see the documentation here:

To unsubscribe from this group and all its topics, send an email to google-doubleclick-for-p...@googlegroups.com.
To post to this group, send email to google-doubleclick...@googlegroups.com.

--

You received this message because you are subscribed to a topic in the Google Groups "Google's DoubleClick for Publishers API Forum" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/google-doubleclick-for-publishers-api/3xwCg6UohMo/unsubscribe.

To unsubscribe from this group and all its topics, send an email to google-doubleclick-for-p...@googlegroups.com.
To post to this group, send email to google-doubleclick...@googlegroups.com.

René Simon

unread,
Oct 17, 2014, 3:48:51 AM10/17/14
to google-doubleclick...@googlegroups.com, dfpapi-advi...@google.com, rene.si...@gmail.com
Thanks Aaron, that was the a next step.

When I used the curl, if got:
{
  "error" : "invalid_request",
  "error_description" : "Missing parameter: redirect_uri"
}

Than I executed:
curl --data "grant_type=authorization_code&client_id=REDACTED&clien_secret=REDACTED&code=REDACTED&redirect_uri=urn:ietf:wg:oauth:2.0:oob " https://accounts.google.com/o/oauth2/token

And got:
{
  "error" : "invalid_request",
  "error_description" : "Invalid parameter value for redirect_uri: Missing authority: urn:ietf:wg:oauth:2.0:oob "
}

What can I do against this?

Sorry. I hope my questions are ok and seem not so dumb. :-)

To unsubscribe from this group and all its topics, send an email to google-doubleclick-for-publishers-api+unsubscribe@googlegroups.com.
To post to this group, send email to google-doubleclick-for-publishers-api@googlegroups.com.

--
You received this message because you are subscribed to a topic in the Google Groups "Google's DoubleClick for Publishers API Forum" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/google-doubleclick-for-publishers-api/3xwCg6UohMo/unsubscribe.

To unsubscribe from this group and all its topics, send an email to google-doubleclick-for-publishers-api+unsubscribe@googlegroups.com.
To post to this group, send email to google-doubleclick-for-publishers-api@googlegroups.com.

Siladi, Aaron

unread,
Oct 17, 2014, 11:31:40 AM10/17/14
to rene.si...@gmail.com, google-doubleclick...@googlegroups.com, dfpapi-advi...@google.com

Rene

 

I used same redirect_uri in my request(sorry, cut and paste error) and it worked.  So the only thing I can think of is maybe check the app settings in the console, you should see that same exact string listed under “redirect uris”.

 

Thanks

Aaron

 

From: google-doubleclick...@googlegroups.com [mailto:google-doubleclick...@googlegroups.com] On Behalf Of René Simon
Sent: Friday, October 17, 2014 12:49 AM
To: google-doubleclick...@googlegroups.com
Cc: dfpapi-advi...@google.com; rene.si...@gmail.com
Subject: Re: Google DFP Client for Node.JS

 

Thanks Aaron, that was the a next step.

To unsubscribe from this group and all its topics, send an email to google-doubleclick-for-p...@googlegroups.com.
To post to this group, send email to google-doubleclick...@googlegroups.com.

--
You received this message because you are subscribed to a topic in the Google Groups "Google's DoubleClick for Publishers API Forum" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/google-doubleclick-for-publishers-api/3xwCg6UohMo/unsubscribe.

To unsubscribe from this group and all its topics, send an email to google-doubleclick-for-p...@googlegroups.com.
To post to this group, send email to google-doubleclick...@googlegroups.com.

--
You received this message because you are subscribed to a topic in the Google Groups "Google's DoubleClick for Publishers API Forum" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/google-doubleclick-for-publishers-api/3xwCg6UohMo/unsubscribe.

To unsubscribe from this group and all its topics, send an email to google-doubleclick-for-p...@googlegroups.com.
To post to this group, send email to google-doubleclick...@googlegroups.com.

Andre de Souza

unread,
Oct 17, 2014, 11:52:47 AM10/17/14
to Siladi, Aaron, rene.si...@gmail.com, google-doubleclick...@googlegroups.com, dfpapi-advi...@google.com
What you have specified in your redirect_uri does not look like a valid URL.

René Simon

unread,
Oct 28, 2014, 4:15:17 AM10/28/14
to google-doubleclick...@googlegroups.com, rene.si...@gmail.com, dfpapi-advi...@google.com
Hallo Aaron,

I found the error, finally.

Now I get the following error:
{
  "error" : "invalid_grant"
}

Can you help?


Am Freitag, 17. Oktober 2014 17:31:40 UTC+2 schrieb Aaron Siladi:

Rene

 

I used same redirect_uri in my request(sorry, cut and paste error) and it worked.  So the only thing I can think of is maybe check the app settings in the console, you should see that same exact string listed under “redirect uris”.

To unsubscribe from this group and all its topics, send an email to google-doubleclick-for-publishers-api+unsubscribe@googlegroups.com.
To post to this group, send email to google-doubleclick-for-publishers-api@googlegroups.com.

--
You received this message because you are subscribed to a topic in the Google Groups "Google's DoubleClick for Publishers API Forum" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/google-doubleclick-for-publishers-api/3xwCg6UohMo/unsubscribe.

To unsubscribe from this group and all its topics, send an email to google-doubleclick-for-publishers-api+unsubscribe@googlegroups.com.
To post to this group, send email to google-doubleclick-for-publishers-api@googlegroups.com.

--
You received this message because you are subscribed to a topic in the Google Groups "Google's DoubleClick for Publishers API Forum" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/google-doubleclick-for-publishers-api/3xwCg6UohMo/unsubscribe.

To unsubscribe from this group and all its topics, send an email to google-doubleclick-for-publishers-api+unsubscribe@googlegroups.com.
To post to this group, send email to google-doubleclick-for-publishers-api@googlegroups.com.

...

Aaron Siladi

unread,
Oct 29, 2014, 1:53:08 PM10/29/14
to google-doubleclick...@googlegroups.com, rene.si...@gmail.com, dfpapi-advi...@google.com
Not sure what the problem is, the earlier command I sent should be working fine, given all the strings (client ID, etc) are valid

curl --data "grant_type=authorization_code&client_id=REDACTED&client_secret=REDACTED&code=REDACTED" https://accounts.google.com/o/oauth2/token

You may try stackoverflow.com, be sure to post exact details of what you tried including error messages, etc. 

Sorry can't help more. 

-Aaron

rene....@softgames.de

unread,
May 5, 2015, 4:59:24 AM5/5/15
to google-doubleclick...@googlegroups.com, rene.si...@gmail.com, dfpapi-advi...@google.com
Sorry for the late answer. I found the problem a while back. When I remember correctly it was a typo of some sort.

To document a way to do this if someone else has this problem here is my final solution:
I wrote two scripts to get the refresh token.
First "generate-authentification-url":
var google = require('googleapis');

var OAuth2 = google.auth.OAuth2;


var url = oauth2Client.generateAuthUrl({
   access_type
: 'offline',
   scope
: ['https://www.googleapis.com/auth/dfp']
});
console
.log(url);

Here you can easily add more scopes to the array if needed.

After running this script you get the url with which you can get the CODE.

After getting this CODE you can edit and run the following script
var google = require('googleapis');
var OAuth2 = google.auth.OAuth2;

var oauth2Client = new OAuth2('{clientId}', '{clientSecret}', '{redirectUri}');
oauth2Client
.getToken('{CODE}', function(error, tokens) {
 
if (error) {
    console
.error(error);
 
} else {
    console
.log(tokens);
 
}
});

You have to replace the values in {}.

In the output you can find the refresh token.

rene....@softgames.de

unread,
May 5, 2015, 5:01:56 AM5/5/15
to google-doubleclick...@googlegroups.com
I'm trying to use the CustomTargetingService service action: performCustomTargetingValueAction, but I can't find a way to handle the abstract customTargetingValueAction.
There I must set the xsi:type to DeleteCustomTargetingValues somehow.
Can someone help me with this or is it not possible to handle abstract elements?

Siladi, Aaron

unread,
May 5, 2015, 2:40:31 PM5/5/15
to google-doubleclick...@googlegroups.com, rene....@softgames.de

You can.  Create the request body like this:


{

  attributes:

    {

      "xsi:type": "nameOfTheAction"

    },

    filterStatement: "filter statement here..."

}


One trick you can use in this type of situation, is make same request using officially supported DFP client, and turn on debugging, you can see the XML that official client creates and structure your JSON same way.  


Thanks,

Aaron



Subject: Re: Google DFP Client for Node.JS
--
You received this message because you are subscribed to a topic in the Google Groups "Google's DoubleClick for Publishers API Forum" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/google-doubleclick-for-publishers-api/3xwCg6UohMo/unsubscribe.
To unsubscribe from this group and all its topics, send an email to google-doubleclick-for-p...@googlegroups.com.
To post to this group, send email to google-doubleclick...@googlegroups.com.

rene....@softgames.de

unread,
May 7, 2015, 3:14:43 AM5/7/15
to google-doubleclick...@googlegroups.com, rene....@softgames.de
Thanks for the help again.

My input now was:
{
  customTargetingValueAction
: {
    attributes
: { 'xsi:type': 'DeleteCustomTargetingValues' }
 
},
  filterStatement
: {
    query
: 'WHERE customTargetingKeyId = \'' + keyId + '\' AND name IN (\'' + valueNames.join('\',\'') + '\')'
 
}
}

It works greate.

Also thanks for the debugging tip. I knew how the soap should look like, since I read the wsdl file, but I did not know how the JSON must look like so that the module creates the correct SOAP/XML-Request.




On Tuesday, May 5, 2015 at 8:40:31 PM UTC+2, Aaron Siladi wrote:

You can.  Create the request body like this:


{

  attributes:

    {

      "xsi:type": "nameOfTheAction"

    },

    filterStatement: "filter statement here..."

}


One trick you can use in this type of situation, is make same request using officially supported DFP client, and turn on debugging, you can see the XML that official client creates and structure your JSON same way.  


Thanks,

Aaron



Sent: Tuesday, May 05, 2015 2:01 AM

Subject: Re: Google DFP Client for Node.JS
I'm trying to use the CustomTargetingService service action: performCustomTargetingValueAction, but I can't find a way to handle the abstract customTargetingValueAction.
There I must set the xsi:type to DeleteCustomTargetingValues somehow.
Can someone help me with this or is it not possible to handle abstract elements?

On Wednesday, May 21, 2014 at 3:13:07 AM UTC+2, Roy Pereira wrote:
We just made public a GitHub repo for a Node.JS DFP client at https://github.com/ShinyAds/node-google-dfp.

You can install is by running "npm install node-google-dfp".

This node.JS client leverages Google's 'googleapis' node.JS client for OAUTH and leverage's DFP's Soap schema heavily, so it should be future-proof.

Let us know what you think and please help making it better by contributing.





--
You received this message because you are subscribed to a topic in the Google Groups "Google's DoubleClick for Publishers API Forum" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/google-doubleclick-for-publishers-api/3xwCg6UohMo/unsubscribe.
To unsubscribe from this group and all its topics, send an email to google-doubleclick-for-publishers-api+unsubscribe@googlegroups.com.
To post to this group, send email to google-doubleclick-for-publishers-api@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages