Search in sources :

Example 6 with GraphObjectList

use of com.facebook.model.GraphObjectList in project Klyph by jonathangerbaud.

the class Response method createResponseFromObject.

private static Response createResponseFromObject(Request request, HttpURLConnection connection, Object object, boolean isFromCache, Object originalResult) throws JSONException {
    if (object instanceof JSONObject) {
        JSONObject jsonObject = (JSONObject) object;
        FacebookRequestError error = FacebookRequestError.checkResponseAndCreateError(jsonObject, originalResult, connection);
        if (error != null) {
            if (error.getErrorCode() == INVALID_SESSION_FACEBOOK_ERROR_CODE) {
                Session session = request.getSession();
                if (session != null) {
                    session.closeAndClearTokenInformation();
                }
            }
            return new Response(request, connection, error);
        }
        Object body = Utility.getStringPropertyAsJSON(jsonObject, BODY_KEY, NON_JSON_RESPONSE_PROPERTY);
        if (body instanceof JSONObject) {
            GraphObject graphObject = GraphObject.Factory.create((JSONObject) body);
            return new Response(request, connection, graphObject, isFromCache);
        } else if (body instanceof JSONArray) {
            GraphObjectList<GraphObject> graphObjectList = GraphObject.Factory.createList((JSONArray) body, GraphObject.class);
            return new Response(request, connection, graphObjectList, isFromCache);
        }
        // We didn't get a body we understand how to handle, so pretend we got nothing.
        object = JSONObject.NULL;
    }
    if (object == JSONObject.NULL) {
        return new Response(request, connection, (GraphObject) null, isFromCache);
    } else {
        throw new FacebookException("Got unexpected object type in response, class: " + object.getClass().getSimpleName());
    }
}
Also used : GraphObjectList(com.facebook.model.GraphObjectList) JSONObject(org.json.JSONObject) JSONArray(org.json.JSONArray) GraphObject(com.facebook.model.GraphObject) JSONObject(org.json.JSONObject) GraphObject(com.facebook.model.GraphObject)

Aggregations

GraphObject (com.facebook.model.GraphObject)6 GraphObjectList (com.facebook.model.GraphObjectList)6 JSONArray (org.json.JSONArray)4 JSONObject (org.json.JSONObject)4 ActivityNotFoundException (android.content.ActivityNotFoundException)2 GraphMultiResult (com.facebook.model.GraphMultiResult)2 GraphUser (com.facebook.model.GraphUser)2 JSONException (org.json.JSONException)2