How to get .csv report in a readable format

82 views
Skip to first unread message

Daniel Mallory

unread,
Mar 26, 2018, 10:44:34 AM3/26/18
to Google's DoubleClick for Publishers API Forum
I am trying to create a simple report in PHP using the sample code found here: https://developers.google.com/doubleclick-publishers/docs/reporting

I have built my report, and I am successfully able to download the report in .csv.gz format as shown in the example. If I manually unzip the gzipped file and open it in Excel I can see that the results are as I expect them to be. However, I need to manipulate this data in PHP. The documentation suggests the following code:

$report = fopen($filePath, 'r');
while (!feof($report)){
   echo fgetcsv
($report);
}
fclose
($report);

However, this code of course doesn't work because the file is gzipped. Please could you advise if there is a way to get this data in a non compressed format, or to uncompress the file in PHP. I would also suggest your documentation should be updated to reflect this.

Nicholas Figeac (DFP API Team)

unread,
Mar 26, 2018, 12:15:48 PM3/26/18
to Google's DoubleClick for Publishers API Forum
Hello,

You can download the report as a regular .csv file by removing .gz from the file name and update ReportDownloadOptions.useGzipCompression to false or you can manually decompress the file to a directory that will be used for extra processing. Our documentation has a note that the file should not be compressed when using that example. We assume you have decompressed the file in a directory before trying to use PHP to read it. 

Thanks,
Nicholas Figeac, DFP API Team

Daniel Mallory

unread,
Mar 26, 2018, 12:18:53 PM3/26/18
to Google's DoubleClick for Publishers API Forum
Hi Nicholas, 

Thanks for your reply. I will try setting that option to false. And yes you are correct, I missed that line in the documentation! 

Thanks again
Dan
Reply all
Reply to author
Forward
0 new messages