FacebookJsonRestClientpublic class FacebookJsonRestClient extends ExtensibleClient A FacebookRestClient that uses the JSON result format. This means
results from calls to the Facebook API are returned as
JSON and
transformed into Java Object 's. |
Constructors Summary |
---|
public FacebookJsonRestClient(String apiKey, String secret)Constructor.
this(SERVER_URL, apiKey, secret, null);
| public FacebookJsonRestClient(String apiKey, String secret, String sessionKey)Constructor.
this(SERVER_URL, apiKey, secret, sessionKey);
| public FacebookJsonRestClient(String serverAddr, String apiKey, String secret, String sessionKey)Constructor.
this(new URL(serverAddr), apiKey, secret, sessionKey);
| public FacebookJsonRestClient(URL serverUrl, String apiKey, String secret, String sessionKey)Constructor.
super(serverUrl, apiKey, secret, sessionKey);
|
Methods Summary |
---|
public java.lang.String | auth_getSession(java.lang.String authToken)Sets the session information (sessionKey) using the token from auth_createToken.
if (null != this._sessionKey) {
return this._sessionKey;
}
JSONObject d = (JSONObject)
this.callMethod(FacebookMethod.AUTH_GET_SESSION,
new Pair<String, CharSequence>("auth_token", authToken.toString()));
try {
this._sessionKey = (String) d.get("session_key");
Object uid = d.get("uid");
try {
this._userId = (Integer) uid;
} catch (ClassCastException cce) {
this._userId = Integer.parseInt((String) uid);
}
if (this.isDesktop()) {
this._sessionSecret = (String) d.get("secret");
}
}
catch (Exception ignored) {}
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 boolean | extractBoolean(java.lang.Object val)Extracts a Boolean from a result that consists of a Boolean only.
try {
if (val instanceof String) {
return ! ((val == null) || (val.equals("false")) || (val.equals("0")));
}
return ((Long)val != 0l);
} catch (ClassCastException cce) {
logException(cce);
return false;
}
| protected int | extractInt(java.lang.Object val)Extracts an Integer from a result that consists of an Integer only.
try {
if (val instanceof String) {
//shouldn't happen, really
return Integer.parseInt((String)val);
}
if (val instanceof Long) {
//this one will happen, the parse method parses all numbers as longs
return ((Long)val).intValue();
}
return (Integer) val;
} catch (ClassCastException cce) {
logException(cce);
return 0;
}
| protected java.lang.Long | extractLong(java.lang.Object val)Extracts a Long from a result that consists of an Long only.
try {
if (val instanceof String) {
//shouldn't happen, really
return Long.parseLong((String)val);
}
return (Long) val;
} catch (ClassCastException cce) {
logException(cce);
return null;
}
| public java.lang.String | extractString(java.lang.Object val)Extracts a String from a result consisting entirely of a String.
try {
return (String) val;
} catch (ClassCastException cce) {
logException(cce);
return null;
}
| protected java.net.URL | extractURL(java.lang.Object url)Extracts a URL from a result that consists of a URL only.
For JSON, that result is simply a String.
if (!(url instanceof String)) {
return null;
}
return (null == url || "".equals(url)) ? null : new URL( (String) url);
| public java.lang.String | getResponseFormat()The response format in which results to FacebookMethod calls are returned
return "json";
| public java.util.List | marketplace_getListings(java.util.List listingIds, java.util.List uids)
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.List | marketplace_getSubCategories()
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.List | marketplace_search(com.facebook.api.MarketListingCategory category, com.facebook.api.MarketListingSubcategory subcategory, java.lang.String searchTerm)
throw new FacebookException(ErrorCode.GEN_UNKNOWN_METHOD, "The FacebookJsonRestClient does not support this API call. " +
"Please use an instance of FacebookRestClient instead.");
| protected java.lang.Object | parseCallResult(java.io.InputStream data, com.facebook.api.IFacebookMethod method)Parses the result of an API call from JSON into Java Objects.
BufferedReader in = new BufferedReader(new InputStreamReader(data, "UTF-8"));
StringBuffer buffer = new StringBuffer();
String line;
while ((line = in.readLine()) != null) {
buffer.append(line);
}
String jsonResp = new String(buffer);
Object json = null;
if (this.rawResponse.matches("[\\{\\[].*[\\}\\]]")) {
try {
if (this.rawResponse.matches("\\{.*\\}")) {
json = new JSONObject(jsonResp);
}
else {
json = new JSONArray(jsonResp);
}
}
catch (Exception ignored) { ignored.printStackTrace(); }
}
else {
if (this.rawResponse.startsWith("\"")) {
this.rawResponse = this.rawResponse.substring(1);
}
if (this.rawResponse.endsWith("\"")) {
this.rawResponse = this.rawResponse.substring(0, this.rawResponse.length() - 1);
}
try {
//it's either a number...
json = Long.parseLong(this.rawResponse);
}
catch (Exception e) {
//...or a string
json = this.rawResponse;
}
}
if (isDebug()) {
log(method.methodName() + ": " + (null != json ? json.toString() : "null"));
}
if (json instanceof JSONObject) {
JSONObject jsonObj = (JSONObject) json;
try {
Integer errorCode = (Integer) jsonObj.get("error_code");
if (errorCode != null) {
String message = (String) jsonObj.get("error_msg");
throw new FacebookException(errorCode, message);
}
}
catch (JSONException ignored) {
//the call completed normally
}
}
return json;
| 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.");
|
|