vitordelfino

Cadastro via api facebook

May 23rd, 2017
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 4.54 KB | None | 0 0
  1. callbackManager = CallbackManager.Factory.create();
  2.         loginButton = (LoginButton) findViewById(R.id.login_button);
  3.         loginButton.setReadPermissions(Arrays.asList("public_profile","user_birthday"));
  4.         loginButton.registerCallback(callbackManager, new FacebookCallback<LoginResult>() {
  5.             @Override
  6.             public void onSuccess(LoginResult loginResult) {
  7.                 GraphRequest request = GraphRequest.newMeRequest(
  8.                         loginResult.getAccessToken(),
  9.                         new GraphRequest.GraphJSONObjectCallback() {
  10.                             @Override
  11.                             public void onCompleted(
  12.                                     JSONObject object,
  13.                                     GraphResponse response) {
  14.                                 JSONObject jo = new JSONObject();
  15.                                 try {
  16.                                     Log.d(TAG, "onCompleted: " + object);
  17.                                     jo.put("facebookId", object.getString("id"));
  18.                                     jo.put("urlPicture", Profile.getCurrentProfile().getProfilePictureUri(100,100).toString());
  19.                                     jo.put("nome", object.getString("name"));
  20.                                 } catch (JSONException e) {
  21.                                     e.printStackTrace();
  22.                                 }
  23.                                 RealizaRequisicao.getInstance().postJson(Login.this,
  24.                                         SppdTools.getInstance().getEndPoint() + "/passageiro/cadastrarComFacebook/",
  25.                                         jo, new VolleyCallbackObject() {
  26.                                             @Override
  27.                                             public void onSuccess(JSONObject result) throws JSONException, IOException {
  28.                                                 if(result.getBoolean("retorno")){
  29.                                                     String msg = result.getString("statusRetorno");
  30.                                                     result = result.getJSONObject("passageiro");
  31.                                                     passageiro.setCodPassageiro(result.getInt("codPassageiro"));
  32.                                                     passageiro.setNome(result.getString("nome"));
  33.                                                     passageiro.setCpf(result.getString("cpf"));
  34.                                                     passageiro.setRg(result.getString("rg"));
  35.                                                     passageiro.setLogradouro(result.getString("logradouro"));
  36.                                                     passageiro.setNumero(result.getString("numero"));
  37.                                                     passageiro.setComplemento(result.getString("complemento"));
  38.                                                     passageiro.setCep(result.getString("cep"));
  39.                                                     passageiro.setBairro(result.getString("bairro"));
  40.                                                     passageiro.setMunicipio(result.getString("municipio"));
  41.                                                     passageiro.setNascimento(result.getString("nascimento"));
  42.                                                     passageiro.setDeficiente(result.getBoolean("deficiente"));
  43.                                                     passageiro.setFacebookId(result.getString("facebookId"));
  44.                                                     passageiro.setUrlPicture(result.getString("urlPicture"));
  45.                                                     Toast.makeText(Login.this, msg, Toast.LENGTH_SHORT).show();
  46.                                                     Intent intent = new Intent(Login.this, Simulador.class);
  47.                                                     intent.putExtra("passageiro", passageiro);
  48.                                                     intent.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
  49.                                                     startActivity(intent);
  50.                                                     finish();
  51.  
  52.                                                 }
  53.                                             }
  54.                                         });
  55.                             }
  56.                         });
  57.                 Bundle parameters = new Bundle();
  58.                 parameters.putString("fields", "id,name,link,birthday");
  59.                 request.setParameters(parameters);
  60.                 request.executeAsync();
  61.  
  62.             }
Advertisement
Add Comment
Please, Sign In to add comment