private void pegarUsuario() { String usuario = "me"; System.out.println("Entrou no pegar Usuario"); RequestBatch requestBatch = new RequestBatch(); System.out.println(Session.getActiveSession()); requestBatch.add( new Request( Session.getActiveSession(), usuario, null, null, new Request.Callback() { public void onCompleted(Response response) { GraphObject graphObject = response.getGraphObject(); System.out.println("Entrou no oncompleted do PegarUsuario"); if (graphObject != null) { System.out.println("Entrou no if do graphObject"); if (graphObject.getProperty("id") != null) { Banco banco = new Banco(TelaFacebook.this); TelaFacebook.nome = (String) graphObject.getProperty("name"); TelaFacebook.email = (String) graphObject.getProperty("email"); TelaFacebook.aniversario = (String) graphObject.getProperty("birthday"); System.out.println( "Nome Usuário : " + nome + " Email: " + email + " Aniversário: " + aniversario); if (email == null) { email = ((String) graphObject.getProperty("first_name")) + "@"; } if (aniversario == null) { aniversario = "01/01/2014"; } if (banco.idUsuario(email) == null) { banco.cadastrarUsuario( nome, aniversario, email, "12345", "Homem", "Show", "Esporte", "Teatro"); } Usuario.setId(banco.idUsuario(email)); System.out.println("Logado"); Toast.makeText(TelaFacebook.this, "Usuário Logado", Toast.LENGTH_SHORT).show(); Intent intent = new Intent(TelaFacebook.this, TelaPrincipal.class); startActivity(intent); } } } })); requestBatch.executeAsync(); }
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()); } } }