大家好!:) 我正在开发一项服务,该服务可以从 Facebook API 中获取喜欢、分享等的数量。但是有一个问题,因为我从 fqlResponse.getChild() 得到了一个空指针异常。
我认为自动检测xmls doctype有问题,所以我手动定义了doctype,但问题仍然存在。也许 facebooks xml doctype 不正确?下面是捕捉方法:
public void refreshLikesSharesClicksAndTotal() throws JDOMException, IOException {
URL fqlURL = new URL("https://api.facebook.com/method/fql.query?query=select like_count, total_count, share_count, click_count from link_stat where url=\"" + this.url.toString() + "\"");
Document inputXML = new SAXBuilder().build(fqlURL);
DocType docType = new DocType("xml", "http://www.w3.org/2001/XMLSchema-instance");
inputXML.setDocType(docType);
Element fqlResponse = inputXML.getRootElement().getChild("link_stat");
Element likes = fqlResponse.getChild("like_count");
logger.info("Likes: " + likes.getText());
Element shares = fqlResponse.getChild("share_count");
Element clicks = fqlResponse.getChild("click_count");
Element total = fqlResponse.getChild("total_count");
this.likes = Integer.parseInt(likes.getText());
this.shares = Integer.parseInt(shares.getText());
this.clicks = Integer.parseInt(clicks.getText());
this.total = Integer.parseInt(total.getText());
}
德语问题描述: http ://www.java-forum.org/xml-co/118648-problem-beim-parsen-facebook-xml.html
感谢帮助!whitenexx