StevenMMortimer / rdfp

This R package connects the DoubleClick for Publishers API from R
https://stevenmmortimer.github.io/rdfp/
Other
16 stars 5 forks source link

Error in running the reporting example #2

Closed robotosize closed 6 years ago

robotosize commented 7 years ago

First, thanks a lot for this package.

I'm getting the following error when running your reporting example (the expanded one):

> report_dat <- dfp_report_url_to_dataframe(report_url=dfp_getReportDownloadURL_result, 
+                                           exportFormat='CSV_DUMP')
Error in curl_download(url = report_url, destfile = temp_destination) : 
  Argument 'url' must be string.

It seems that by that stage the dfp_getReportDownloadURL_result is a dataframe and not a string.

I'm noob in R, so maybe I'm doing something wrong.

Thanks!

StevenMMortimer commented 7 years ago

Thanks @robotosize. Google has been switching things up the last couple versions, so no doubt it's probably an issue with the way the R code was written to expect a result. I'm a little busy at the moment, but will try to fix soon. You might want to simply parse out dfp_getReportDownloadURL_result to get the URL as a string, then pass that along like this:

url_string <- dfp_getReportDownloadURL_result$url
report_dat <- dfp_report_url_to_dataframe(report_url=url_string,exportFormat='CSV_DUMP')                                  
robotosize commented 7 years ago

Thanks @ReportMort. In order to get the URL as a string I had to change it to: url_string <- dfp_getReportDownloadURL_result$x But it seems that Google changed the output format (calling the url_string from the browser downloads a csv.gz file), and maybe that causes the following error when trying to convert the output to a data frame: > report_dat <- dfp_report_url_to_dataframe(report_url=url_string,exportFormat='CSV_DUMP') Error in scan(file, what, nmax, sep, dec, quote, skip, nlines, na.strings, : line 1 did not have 4 elements In addition: Warning messages: 1: In read.table(gzfile(temp_destination, encoding = this_encoding), : invalid input found on input connection '/var/folders/86/j483dg0111nfnk114m8msgrh0000gn/T//Rtmpr6dOHG/file1a8a39317c4' 2: In read.table(gzfile(temp_destination, encoding = this_encoding), : incomplete final line found by readTableHeader on '/var/folders/86/j483dg0111nfnk114m8msgrh0000gn/T//Rtmpr6dOHG/file1a8a39317c4'

StevenMMortimer commented 6 years ago

@robotosize You'll need to specify some reportDownloadOptions when you get the URL. Google has required more information when asking for the report URL so that it knows what to provide. Follow the example flow below:

# provide the report specifications
report_request_data <- list(reportJob=
                              list(reportQuery=
                                     list(dimensions='MONTH_AND_YEAR', 
                                          dimensions='AD_UNIT_ID',
                                          adUnitView='FLAT',
                                          columns='TOTAL_INVENTORY_LEVEL_IMPRESSIONS', 
                                          startDate=list(year=2016, month=1, day=1),
                                          endDate=list(year=2016, month=1, day=31),
                                          dateRangeType='CUSTOM_DATE')))

# run report
report_job_result <- dfp_runReportJob(report_request_data)

# make sure that its completed before pulling down
status_request_data <- list(reportJobId= report_job_result $id)
report_job_status <- dfp_getReportJobStatus(status_request_data)

# specify how to download the data
request_data <- list(reportJobId= report_job_result $id, 
                     reportDownloadOptions=list(exportFormat='CSV_DUMP', 
                                                includeTotalsRow='true'))
# get the url
download_url_result <- dfp_getReportDownloadUrlWithOptions(request_data)

# pass that url back to DFP to get the file
report_dat <- dfp_report_url_to_dataframe(report_url=download_url_resultx, 
                                          exportFormat='CSV_DUMP')