Hi everyone,
I'm new to this forum and topic, so please forgive me if I have posted this in the wrong location or if this is a very newbie question.
I'm attempting to migrate some Java based tools that use the AdWords API from using AdWordsUser (having the email/password in the source) to OAuth2, getting the credential using setServiceAccountPrivateKeyFromP12File.
Since I no longer have an AdWords user, I was looking to change from this:
ReportDownloadResponse response = ReportUtils.downloadReport(user, reportDefinition, fos);
to this:
ReportDownloadResponse response = new ReportDownloader(adwordsApiSession).downloadReport(reportDefinition);
It seems like my OAuth validation is successful (I can mess up the user name, for example, and I will get a message that validation failed), but my download fails with the following message/stack trace (UrlUpdater is the name of my class):
[Fatal Error] :2:12: Open quote is expected for attribute "{1}" associated with an element type "lang".
[08 Feb 2013 13:33:35,331-report_download:ERROR:AWT-EventQueue-0] Couldn't process XML into a Document
HTTP Response Code: 503, ErrorText: <!DOCTYPE html>
org.xml.sax.SAXParseException: Open quote is expected for attribute "{1}" associated with an element type "lang".
<html lang=en>
<meta charset=utf-8>
<meta name=viewport content="initial-scale=1, minimum-scale=1, width=device-width">
<title>Error 503 (Server Error)!!1</title>
<style>
*{margin:0;padding:0}html,code{font:15px/22px arial,sans-serif}html{background:#fff;color:#222;padding:15px}body{margin:7% auto 0;max-width:390px;min-height:180px;padding:30px 0 15px}* > body{background:url(//www.google.com/images/errors/robot.png) 100% 5px no-repeat;padding-right:205px}p{margin:11px 0 22px;overflow:hidden}ins{color:#777;text-decoration:none}a img{border:0}@media screen and (max-width:772px){body{background:none;margin-top:0;max-width:none;padding-right:0}}
</style>
<a href=//www.google.com/><img src=//www.google.com/images/errors/logo_sm.gif alt=Google></a>
<p><b>503.</b> <ins>That’s an error.</ins>
<p>The service you requested is not available at this time.<p>Service error -27. <ins>That’s all we know.</ins>
at com.sun.org.apache.xerces.internal.parsers.DOMParser.parse(DOMParser.java:246)
at com.google.api.ads.adwords.lib.utils.v201209.ReportDownloader.handleResponse(ReportDownloader.java:119)
at com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderImpl.parse(DocumentBuilderImpl.java:284)
at com.google.api.ads.adwords.lib.utils.v201209.ReportDownloader.downloadReport(ReportDownloader.java:93)
at urlupdater.UrlUpdater.downloadAdHocReport(UrlUpdater.java:487)
at javax.xml.parsers.DocumentBuilder.parse(DocumentBuilder.java:124)
at urlupdater.UrlUpdater.<init>(UrlUpdater.java:441)
at com.google.api.ads.adwords.lib.utils.XmlFieldExtractor.getDocument(XmlFieldExtractor.java:124)
at urlupdater.AccountSelector$2$1.run(AccountSelector.java:86)
at com.google.api.ads.adwords.lib.utils.XmlFieldExtractor.extract(XmlFieldExtractor.java:80)
at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:209)
at com.google.api.ads.adwords.lib.utils.v201209.ReportDownloader.handleResponse(ReportDownloader.java:121)
at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:702)
at com.google.api.ads.adwords.lib.utils.v201209.ReportDownloader.downloadReport(ReportDownloader.java:93)
Does anyone know what I might be doing wrong? I can post more details about my reportDefinition if it seems necessary.
Thank you!
Charlie
... try ...
Selector selector = new Selector();List<String> selectorFields = selector.getFields();selectorFields.addAll(Arrays.asList(ADWORDS_FIELDS));Predicate campaignStatusPredicate = generatePredicate("CampaignStatus", PredicateOperator.NOT_IN, new String[]{"DELETED"});Predicate adGroupStatusPredicate = generatePredicate("AdGroupStatus", PredicateOperator.NOT_IN, new String[]{"DELETED"});Predicate statusPredicate = generatePredicate("Status", PredicateOperator.NOT_IN, new String[]{"DISABLED"});Predicate adTypePredicate = generatePredicate("AdType", PredicateOperator.IN, new String[]{"TEXT_AD"});// add predicates to selectorList<Predicate> predicatesList = selector.getPredicates();predicatesList.addAll(Arrays.asList(new Predicate[]{campaignStatusPredicate, adGroupStatusPredicate, statusPredicate, adTypePredicate}));ReportDefinition reportDefinition = new ReportDefinition();reportDefinition.setReportName(REPORT_NAME + " #" + System.currentTimeMillis());reportDefinition.setDateRangeType(ReportDefinitionDateRangeType.TODAY);reportDefinition.setReportType(REPORT_DEFINITION_REPORT_SERVICE);reportDefinition.setDownloadFormat(DownloadFormat.TSV);reportDefinition.setIncludeZeroImpressions(true);reportDefinition.setSelector(selector);FileOutputStream fos = new FileOutputStream(new File(fileName));
ReportDownloadResponse response = new ReportDownloader(adwordsApiSession).downloadReport(reportDefinition);
if (response.getHttpStatus() == HttpURLConnection.HTTP_OK) {Streams.copy(response.getInputStream(), fos);System.out.println("Report successfully downloaded: " + fileName);} else {System.out.println("Report was not downloaded. " + response.getHttpStatus() + ": "+ response.getHttpResponseMessage());}
... catch ...