FacebookXmlRestClientpublic class FacebookXmlRestClient extends ExtensibleClient A FacebookRestClient that uses the XML result format. This means
results from calls to the Facebook API are returned as XML and
transformed into instances of {@link org.w3c.dom.Document}. |
Constructors Summary |
---|
public FacebookXmlRestClient(String apiKey, String secret)Constructor. Don't use this, use FacebookRestClient instead.
this(SERVER_URL, apiKey, secret, null);
| public FacebookXmlRestClient(String apiKey, String secret, String sessionKey)Constructor. Don't use this, use FacebookRestClient instead.
this(SERVER_URL, apiKey, secret, sessionKey);
| public FacebookXmlRestClient(String serverAddr, String apiKey, String secret, String sessionKey)Constructor. Don't use this, use FacebookRestClient instead.
this(new URL(serverAddr), apiKey, secret, sessionKey);
| public FacebookXmlRestClient(URL serverUrl, String apiKey, String secret, String sessionKey)Constructor. Don't use this, use FacebookRestClient instead.
super(serverUrl, apiKey, secret, sessionKey);
|
Methods Summary |
---|
public java.lang.String | auth_getSession(java.lang.String authToken)Call this function to retrieve the session information after your user has
logged in.
if (null != this._sessionKey) {
return this._sessionKey;
}
Document d =
this.callMethod(FacebookMethod.AUTH_GET_SESSION,
new Pair<String, CharSequence>("auth_token", authToken.toString()));
this._sessionKey =
d.getElementsByTagName("session_key").item(0).getFirstChild().getTextContent();
this._userId = Integer.parseInt(d.getElementsByTagName("uid").item(0).getFirstChild().getTextContent());
if (this._isDesktop) {
this._sessionSecret =
d.getElementsByTagName("secret").item(0).getFirstChild().getTextContent();
}
return this._sessionKey;
| public java.lang.String | data_getUserPreference(java.lang.Integer prefId)
throw new FacebookException(ErrorCode.GEN_UNKNOWN_METHOD, "The FacebookJsonRestClient does not support this API call. " +
"Please use an instance of FacebookRestClient instead.");
| public java.util.Map | data_getUserPreferences()
throw new FacebookException(ErrorCode.GEN_UNKNOWN_METHOD, "The FacebookJsonRestClient does not support this API call. " +
"Please use an instance of FacebookRestClient instead.");
| public void | data_setUserPreference(java.lang.Integer prefId, java.lang.String value)
throw new FacebookException(ErrorCode.GEN_UNKNOWN_METHOD, "The FacebookJsonRestClient does not support this API call. " +
"Please use an instance of FacebookRestClient instead.");
| public void | data_setUserPreferences(java.util.Map values, boolean replace)
throw new FacebookException(ErrorCode.GEN_UNKNOWN_METHOD, "The FacebookJsonRestClient does not support this API call. " +
"Please use an instance of FacebookRestClient instead.");
| protected int | extractInt(org.w3c.dom.Document doc)Extracts an Integer from a document that consists of an Integer only.
return Integer.parseInt(doc.getFirstChild().getTextContent());
| protected java.lang.Long | extractLong(org.w3c.dom.Document doc)Extracts a Long from a document that consists of a Long only.
return Long.parseLong(doc.getFirstChild().getTextContent());
| public java.lang.String | extractString(org.w3c.dom.Document d)Extracts a String from a T consisting entirely of a String.
return d.getFirstChild().getTextContent();
| protected java.net.URL | extractURL(org.w3c.dom.Document doc)Extracts a URL from a document that consists of a URL only.
String url = doc.getFirstChild().getTextContent();
return (null == url || "".equals(url)) ? null : new URL(url);
| public java.lang.String | getResponseFormat()The response format in which results to FacebookMethod calls are returned
return "xml";
| public java.util.List | marketplace_getListings(java.util.List listingIds, java.util.List uids)
this.marketplace_getListings(listingIds, uids);
MarketplaceGetListingsResponse resp = (MarketplaceGetListingsResponse)this.getResponsePOJO();
return resp.getListing();
| public java.util.List | marketplace_getSubCategories()
this.marketplace_getSubCategories(null);
MarketplaceGetSubCategoriesResponse resp = (MarketplaceGetSubCategoriesResponse)this.getResponsePOJO();
return resp.getMarketplaceSubcategory();
| public java.util.List | marketplace_search(com.facebook.api.MarketListingCategory category, com.facebook.api.MarketListingSubcategory subcategory, java.lang.String searchTerm)
this.marketplace_search(category.getName(), subcategory.getName(), searchTerm);
MarketplaceSearchResponse resp = (MarketplaceSearchResponse)this.getResponsePOJO();
return resp.getListing();
| protected org.w3c.dom.Document | parseCallResult(java.io.InputStream data, com.facebook.api.IFacebookMethod method)
try {
DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
Document doc = builder.parse(data);
doc.normalizeDocument();
stripEmptyTextNodes(doc);
if (isDebug()) {
FacebookXmlRestClient.printDom(doc, method.methodName() + "| ");
}
NodeList errors = doc.getElementsByTagName(ERROR_TAG);
if (errors.getLength() > 0) {
int errorCode =
Integer.parseInt(errors.item(0).getFirstChild().getFirstChild().getTextContent());
String message = errors.item(0).getFirstChild().getNextSibling().getTextContent();
throw new FacebookException(errorCode, message);
}
return doc;
} catch (ParserConfigurationException ex) {
System.err.println("huh?" + ex);
} catch (SAXException ex) {
throw new IOException("error parsing xml");
}
return null;
| public static void | printDom(org.w3c.dom.Node n, java.lang.String prefix)Prints out the DOM tree.
String outString = prefix;
if (n.getNodeType() == Node.TEXT_NODE) {
outString += "'" + n.getTextContent().trim() + "'";
} else {
outString += n.getNodeName();
}
System.out.println(outString);
NodeList children = n.getChildNodes();
int length = children.getLength();
for (int i = 0; i < length; i++) {
FacebookXmlRestClient.printDom(children.item(i), prefix + " ");
}
| public java.lang.Integer | sms_send(java.lang.String message, java.lang.Integer smsSessionId, boolean makeNewSession)
throw new FacebookException(ErrorCode.GEN_UNKNOWN_METHOD, "The FacebookJsonRestClient does not support this API call. " +
"Please use an instance of FacebookRestClient instead.");
| public java.lang.Integer | sms_send(java.lang.Long userId, java.lang.String message, java.lang.Integer smsSessionId, boolean makeNewSession)
throw new FacebookException(ErrorCode.GEN_UNKNOWN_METHOD, "The FacebookJsonRestClient does not support this API call. " +
"Please use an instance of FacebookRestClient instead.");
| private static void | stripEmptyTextNodes(org.w3c.dom.Node n)Hack...since DOM reads newlines as textnodes we want to strip out those
nodes to make it easier to use the tree.
NodeList children = n.getChildNodes();
int length = children.getLength();
for (int i = 0; i < length; i++) {
Node c = children.item(i);
if (!c.hasChildNodes() && c.getNodeType() == Node.TEXT_NODE &&
c.getTextContent().trim().length() == 0) {
n.removeChild(c);
i--;
length--;
children = n.getChildNodes();
} else {
stripEmptyTextNodes(c);
}
}
|
|