Cannot get all managed customers with java library: 在文件元素內容中找到無效的 XML 字元 (Unicode: 0x8)

128 views
Skip to first unread message

郭文豪

unread,
Sep 25, 2017, 11:42:02 PM9/25/17
to AdWords API Forum

Hi all, 

I cannot fetch all the managed customers, not sure what's wrong 

I've tried a whole day, maybe it's associate with the mcc account ?

Please help us identify the problem.

Thanks.




<dependency>
<groupId>com.google.api-ads</groupId>
<artifactId>ads-lib</artifactId>
<version>RELEASE</version>
</dependency>
<dependency>
<groupId>com.google.api-ads</groupId>
<artifactId>adwords-axis</artifactId>
<version>RELEASE</version>
</dependency>



private static final int PAGE_SIZE = 20;

public static void main(String[] args) throws Exception {
// Generate a refreshable OAuth2 credential.
Credential oAuth2Credential = new OfflineCredentials.Builder()
.forApi(OfflineCredentials.Api.ADWORDS)
.withClientSecrets("client-id", "client-secret")
.withRefreshToken("refresh-token")
.build()
.generateCredential();

// Construct an AdWordsSession.
AdWordsSession session = new AdWordsSession.Builder()
.withDeveloperToken("developer-token")
.withOAuth2Credential(oAuth2Credential)
.withClientCustomerId("client-customer-id")
.build();

AdWordsServicesInterface adWordsServices = AdWordsServices.getInstance();

runExample(adWordsServices, session);
}

public static void runExample(AdWordsServicesInterface adWordsServices, AdWordsSession session)
throws Exception {
// Get the ServicedAccountService.
ManagedCustomerServiceInterface managedCustomerService =
adWordsServices.get(session, ManagedCustomerServiceInterface.class);

// Create selector builder.
int offset = 0;
SelectorBuilder selectorBuilder =
new SelectorBuilder()
.fields(ManagedCustomerField.CustomerId, ManagedCustomerField.Name)
.offset(offset)
.limit(PAGE_SIZE);

// Get results.
ManagedCustomerPage page;

do {
page = managedCustomerService.get(selectorBuilder.build());

if (page.getEntries() != null) {
// Create account tree nodes for each customer.
for (ManagedCustomer customer : page.getEntries()) {
System.out.println(customer.getName() + " " + customer.getCustomerId());
}
}
offset += PAGE_SIZE;
selectorBuilder.increaseOffsetBy(PAGE_SIZE);
} while (offset < page.getTotalNumEntries());
}

郭文豪

unread,
Sep 25, 2017, 11:46:07 PM9/25/17
to AdWords API Forum
Request
====================================


11:21:04.739 [main] INFO com.google.api.ads.adwords.lib.client.AdWordsServiceClient.soapXmlLogger - SOAP request:
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
    <soapenv:Header>
        <ns1:RequestHeader xmlns:ns1="https://adwords.google.com/api/adwords/mcm/v201708" soapenv:mustUnderstand="0">
            <ns2:clientCustomerId xmlns:ns2="https://adwords.google.com/api/adwords/cm/v201708">client-customer-id</ns2:clientCustomerId>
            <ns3:developerToken xmlns:ns3="https://adwords.google.com/api/adwords/cm/v201708">REDACTED</ns3:developerToken>
            <ns4:userAgent xmlns:ns4="https://adwords.google.com/api/adwords/cm/v201708">unknown (AwApi-Java, AdWords-Axis/3.8.0, Common-Java/3.8.0, Axis/1.4, Java/1.8.0_101, maven, SelectorBuilder)</ns4:userAgent>
            <ns5:validateOnly xmlns:ns5="https://adwords.google.com/api/adwords/cm/v201708">false</ns5:validateOnly>
            <ns6:partialFailure xmlns:ns6="https://adwords.google.com/api/adwords/cm/v201708">false</ns6:partialFailure>
        </ns1:RequestHeader>
    </soapenv:Header>
    <soapenv:Body>
            <serviceSelector>
                <ns7:fields xmlns:ns7="https://adwords.google.com/api/adwords/cm/v201708">CustomerId</ns7:fields>
                <ns8:fields xmlns:ns8="https://adwords.google.com/api/adwords/cm/v201708">Name</ns8:fields>
                <ns9:paging xmlns:ns9="https://adwords.google.com/api/adwords/cm/v201708">
                    <ns9:startIndex>1040</ns9:startIndex>
                    <ns9:numberResults>20</ns9:numberResults>
                </ns9:paging>
            </serviceSelector>
        </get>
    </soapenv:Body>
</soapenv:Envelope>


Response
====================================

11:21:04.739 [main] INFO com.google.api.ads.adwords.lib.client.AdWordsServiceClient.soapXmlLogger - SOAP response:
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
    <soapenv:Body>
        <soapenv:Fault>
            <faultcode>soapenv:Server.userException</faultcode>
            <faultstring>org.xml.sax.SAXParseException; lineNumber: 1; columnNumber: 816; 在文件元素內容中找到無效的 XML 字元 (Unicode: 0x8)。</faultstring>
            <detail>
                <ns1:stackTrace xmlns:ns1="http://xml.apache.org/axis/">org.xml.sax.SAXParseException; lineNumber: 1; columnNumber: 816; 在文件元素內容中找到無效的 XML 字元 (Unicode: 0x8)。
at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.createSAXParseException(ErrorHandlerWrapper.java:203)
at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.fatalError(ErrorHandlerWrapper.java:177)
at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(XMLErrorReporter.java:400)
at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(XMLErrorReporter.java:327)
at com.sun.org.apache.xerces.internal.impl.XMLScanner.reportFatalError(XMLScanner.java:1465)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl$FragmentContentDriver.next(XMLDocumentFragmentScannerImpl.java:2920)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(XMLDocumentScannerImpl.java:606)
at com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl.next(XMLNSDocumentScannerImpl.java:118)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(XMLDocumentFragmentScannerImpl.java:504)
at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:848)
at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:777)
at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(XMLParser.java:141)
at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(AbstractSAXParser.java:1213)
at com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl$JAXPSAXParser.parse(SAXParserImpl.java:643)
at com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl.parse(SAXParserImpl.java:327)
at org.apache.axis.encoding.DeserializationContext.parse(DeserializationContext.java:227)
at org.apache.axis.SOAPPart.getAsSOAPEnvelope(SOAPPart.java:696)
at org.apache.axis.Message.getSOAPEnvelope(Message.java:435)
at org.apache.axis.transport.http.HTTPSender.readFromSocket(HTTPSender.java:796)
at org.apache.axis.transport.http.HTTPSender.invoke(HTTPSender.java:144)
at org.apache.axis.strategies.InvocationStrategy.visit(InvocationStrategy.java:32)
at org.apache.axis.SimpleChain.doVisiting(SimpleChain.java:118)
at org.apache.axis.SimpleChain.invoke(SimpleChain.java:83)
at org.apache.axis.client.AxisClient.invoke(AxisClient.java:165)
at org.apache.axis.client.Call.invokeEngine(Call.java:2784)
at org.apache.axis.client.Call.invoke(Call.java:2767)
at org.apache.axis.client.Call.invoke(Call.java:2443)
at org.apache.axis.client.Call.invoke(Call.java:2366)
at org.apache.axis.client.Call.invoke(Call.java:1812)
at com.google.api.ads.adwords.axis.v201708.mcm.ManagedCustomerServiceSoapBindingStub.get(ManagedCustomerServiceSoapBindingStub.java:821)
at sun.reflect.GeneratedMethodAccessor36.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at com.google.api.ads.common.lib.soap.SoapClientHandler.invoke(SoapClientHandler.java:100)
at com.google.api.ads.common.lib.soap.axis.AxisHandler.invokeSoapCall(AxisHandler.java:234)
at com.google.api.ads.common.lib.soap.SoapServiceClient.callSoapClient(SoapServiceClient.java:63)
at com.google.api.ads.common.lib.soap.SoapServiceClient.invoke(SoapServiceClient.java:93)
at com.sun.proxy.$Proxy18.get(Unknown Source)
at tw.com.urad.web.security.Test.runExample(Test.java:57)
at tw.com.urad.web.security.Test.main(Test.java:36)
</ns1:stackTrace>
                <ns2:hostname xmlns:ns2="http://xml.apache.org/axis/">local</ns2:hostname>
            </detail>
        </soapenv:Fault>
    </soapenv:Body>
</soapenv:Envelope>

Nadine Sundquist (AdWords API Team)

unread,
Sep 26, 2017, 12:11:28 PM9/26/17
to AdWords API Forum
Hello,

I found the issue, and it's a tricky one. The good thing is that the request you are making to the API is successful, so there is nothing wrong with your request. The issue is what is being returned. You are successfully getting a response. However, that response has hidden characters in it. When Java tries to parse it, it considers those hidden characters as invalid XML characters, and that is where you are getting the errors. I found one of the reasons, but there may be more than one reason. I'll send you the account with the hidden character issue in a separate, private email. I just wanted to make sure that people reading the forum in the future know to look for hidden characters when this happens.

Best,
Nadine, AdWords API Team

wi...@urad.com.tw

unread,
Feb 7, 2018, 4:04:29 AM2/7/18
to AdWords API Forum
Hi Nadine Sundquist,

I'm curious that is there any update about this issue? We encountered this issue again and again...
Does AdWords API Team have any schedule for solving this issue? (Our manager has been caring about this issue for a while, and we are asked to propose some alternative solutions for this...)
Thanks for your reading.



Nadine Sundquist (AdWords API Team)於 2017年9月27日星期三 UTC+8上午12時11分28秒寫道:

Nadine Sundquist (AdWords API Team)

unread,
Feb 7, 2018, 10:34:45 AM2/7/18
to AdWords API Forum
Hi,

Thank you for getting in contact with me. I was of the understanding that this was more of an occasional issue, and that it didn't happen that often. Now that you're reaching out again, I can see that it is a bit more serious. There currently is no timeline for this. However, since you've raised this as a concern that continues to be a problem, I have raised the issue's priority. May I ask how often this issue happens? Is it something that happens every day, or is it something that happens once a week? The reason I ask is because I ran a query on our logs over the last couple of weeks, and I haven't seen it happening, so I'm wondering if I may be missing it. If you do have a recent example of it, please send me the requestId of an example request that recently failed. If you don't have the requestId, then an example of the request like you did before will work as well.

Thanks,
Nadine, AdWords API Team

Nadine Sundquist (AdWords API Team)

unread,
Aug 24, 2018, 6:43:00 PM8/24/18
to AdWords API and Google Ads API Forum
Hello Everyone,

I know it's been awhile, but I wanted everyone to know that we fixed the root issue where these hidden characters were getting into our system. Over the next couple of months, this should get better as people will not be able to put in characters that will create issues for you. Thank you all for chiming in! 

Take care,
Nadine, AdWords API Team

wi...@urad.com.tw

unread,
Aug 26, 2018, 10:24:10 PM8/26/18
to AdWords API and Google Ads API Forum
Hi Nadine,

I would say this news is never too late :D
Thank you for your effort!


BR,
Wise

Nadine Sundquist (AdWords API Team)於 2018年8月25日星期六 UTC+8上午6時43分00秒寫道:
Reply all
Reply to author
Forward
0 new messages