ReportDownloadResponse as java object

50 views
Skip to first unread message

os...@ebay.com

unread,
Dec 30, 2014, 8:24:40 AM12/30/14
to adwor...@googlegroups.com
Hi all,
I am using Google Adwords api v201409 1.35 java library. I want to know if there is already a class defined in the api where we can store the ReportDownloadResponse input stream. I populate the ReportDefiniton object with some criterias(ReportDefinitonReportType-->Search_Query_Performance_Report) and call ReportDownloader. I get the response as ReportDownloadResponse which contains httpResponseMessage in case of an error and the result as input stream. I need that input stream to be serialized so that I can add keywords to my campaing according to suggested keywords in the search term report.
Thank in advance.

Josh Radcliff (AdWords API Team)

unread,
Dec 30, 2014, 11:12:03 AM12/30/14
to adwor...@googlegroups.com
Hi,

Since the ReportDownloadResponse object gives you access to the InputStream via response.getInputStream(), you can save the contents of that stream wherever you'd like. The DownloadCriteriaReport.java example saves the contents to a file, but you could choose to store the contents elsewhere, e.g., as a blob in a database.

If you simply want to retrieve the bytes in the InputStream as a byte array, you can use the Guava I/O utilities as follows:

      final ReportDownloadResponse response =
          new ReportDownloader(session).downloadReport(reportDefinition);
      ByteArrayOutputStream outStream = new ByteArrayOutputStream();
      new ByteSource() {
        @Override
        public InputStream openStream() throws IOException {
          return response.getInputStream();
        }
      }.copyTo(outStream);
      byte[] contentBytes = outStream.toByteArray();

Note that you cannot serialize the InputStream itself, as that type is not Serializable (it represents the byte source, not the actual contents of the source).

Thanks,
Josh, AdWords API Team
Reply all
Reply to author
Forward
0 new messages