private void publish(JSONArray args, CallbackContext callbackContext) throws JSONException { JSONObject actionParams = args.getJSONObject(0); if (actionParams.has("object")) { RequestBatch requestBatch = new RequestBatch(); OpenGraphObject object = buildOpenGraphObject(actionParams); Request objectRequest = Request.newPostOpenGraphObjectRequest(Session.getActiveSession(), object, null); objectRequest.setBatchEntryName("objectCreate"); OpenGraphAction action = OpenGraphAction.Factory.createForPost(actionParams.getString("action")); action.setMessage(actionParams.getString("message")); action.setProperty("place", actionParams.getLong("place")); action.setExplicitlyShared(actionParams.getBoolean("explicitlyShared")); action.setProperty(actionParams.getString("objectType"), "{result=objectCreate:$.id}"); Request request = Request.newPostOpenGraphActionRequest(Session.getActiveSession(), action, null); request.setBatchEntryDependsOn("objectCreate"); requestBatch.add(objectRequest); requestBatch.add(request); List<Response> responses = requestBatch.executeAndWait(); Response lastResponse = null; for (Response response : responses) { if (response.getError() != null) { callbackContext.error(response.getError().toString()); return; } lastResponse = response; } callbackContext.success(lastResponse.getGraphObject().getInnerJSONObject()); } else { OpenGraphAction action = OpenGraphAction.Factory.createForPost(actionParams.getString("action")); action.setMessage(actionParams.getString("message")); action.setProperty("place", actionParams.getLong("place")); action.setExplicitlyShared(actionParams.getBoolean("explicitlyShared")); action.setProperty(actionParams.getString("objectType"), actionParams.getString("objectId")); Request request = Request.newPostOpenGraphActionRequest(Session.getActiveSession(), action, null); Response response = request.executeAndWait(); if (response.getError() != null) { callbackContext.error(response.getError().toString()); } else { callbackContext.success(response.getGraphObject().getInnerJSONObject()); } } }