Get DMC report in google spreadsheet using google app script

293 views
Skip to first unread message

Ciro Shia

unread,
May 12, 2016, 2:48:36 PM5/12/16
to Google's DoubleClick Campaign Manager API Forum
Hi, I want to use the advanced services in google app script to get my DCM report into google spreadSheet.
Everything I´ve tried to do works perfectly, but I got stuck on the part of downloading the file. Here is my Code:

function testeDcm() {
 
var profileId = xxxxxxxx;
 
var reportId = xxxxxxxx;
 
var fileId = xxxxxxxxxxx;
 
 
var reportUrl =  DoubleClickCampaigns.Files.get(reportId, fileId).urls.apiUrl;
 
 
var token = ScriptApp.getOAuthToken();


 
var headersOptions = {
   
Authorization : 'bearer '  + token
   
};


 
var options = {
    headers
: headersOptions,
    muteHttpExceptions
: false
   
};


 
var csvDoc = UrlFetchApp.fetch(reportUrl, options);
 
 
Logger.log(csvDoc);
 
}



Here is the error:

Request failed for https://www.googleapis.com/dfareporting/v2.4/reports/43204373/files/241592264?alt=media returned code 401. Truncated server response: Invalid Credentials (use muteHttpExceptions option to examine full response) (line 19, file "Code")

Does anyone know what am I doing wrong?

Thank you!!!


Vu Chau (DCM API Team)

unread,
May 12, 2016, 5:54:52 PM5/12/16
to Google's DoubleClick Campaign Manager API Forum
Hi Ciro,

Going by the error message, an "Invalid Credentials" error usually indicates that your access token has expired, or you have authorized for the wrong OAuth scope.  To check if your access token has expired, try logging out and then back in, and rerun the request.

Cheers,

Vu Chau
DCM API Team

Ciro Shia

unread,
May 12, 2016, 6:05:00 PM5/12/16
to Google's DoubleClick Campaign Manager API Forum
Hi!

I´ve tried to log in and out, but I still get the same error. Anyway shouldn´t this parts part of the code guarantee that I have a valid tolken?

var token = ScriptApp.getOAuthToken();

Vu Chau (DCM API Team)

unread,
May 13, 2016, 11:36:09 AM5/13/16
to Google's DoubleClick Campaign Manager API Forum
Hi Ciro,

Thanks for clarifying! I see that in your header, you are sending "bearer".  The header might be case sensitive, so try sending in "Bearer" instead. 

Let us know if that resolves the error,

Vu Chau
DCM API Team

Ciro Shia

unread,
May 13, 2016, 1:28:22 PM5/13/16
to google-doubleclick-...@googlegroups.com
I worked like a charm!! Thank you so very much!!!!!

Ciro Shia
RainMaker - Media Innovation

Logo Jussi

ci...@jussi.com.br

(11) 3033-2286
(11) 98442-4012


Rua Bandeira Paulista, 530, 13º andar
Itaim Bibi - CEP 04532-001 - São Paulo, SP


--
You received this message because you are subscribed to a topic in the Google Groups "Google's DoubleClick Campaign Manager API Forum" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/google-doubleclick-for-advertisers-api/CkwTDybvOJg/unsubscribe.
To unsubscribe from this group and all its topics, send an email to google-doubleclick-for-ad...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages