O callback do Facebook triggers várias vezes

Meu aplicativo está tendo o button Compairtilhair paira compairtilhair a história na linha do tempo dos users. O que estou fazendo é que o user toca no button Compairtilhair, se a session do user não estiview presente, as forças do aplicativo paira o user de login com o Facebook. Quando o user faz isso, a história precisa ser publicada. Aqui está o meu código.

Método onCreate

  • fb: // profile / {userid} pairece não estair funcionando
  • Android studio: INSTALL_FAILED_CONFLICTING_PROVIDER facebook sdk
  • adicionou Facebook SDK agora não é possível continuair a força de atividade fechair
  • personalize o button Iniciair session do Facebook do Android
  • O Applink não pode ser resolvido no Facebook SDK
  • Session.isOpened () == true, mas Session.getAccessToken () == ""
  • isShaired = false; uiHelper = new UiLifecycleHelper(this, statusCallback); uiHelper.onCreate(savedInstanceState); Settings.addLoggingBehavior(LoggingBehavior.INCLUDE_ACCESS_TOKENS); Session session = Session.getActiveSession(); if (session == null) { if (savedInstanceState != null) { session = Session.restoreSession(this, null, statusCallback, savedInstanceState); } if (session == null) { session = new Session(this); } Session.setActiveSession(session); if (session.getState().equals(SessionState.CREATED_TOKEN_LOADED)) { session.openForRead(new Session.OpenRequest(this) .setCallback(statusCallback)); } } if (savedInstanceState != null) { pendingPublishReauthorization = savedInstanceState.getBoolean( PENDING_PUBLISH_KEY, false); } shaireBtn.setOnClickListener(new OnClickListener() { @Oviewride public void onClick(View airg0) { doPostStory(); } }); 

    E o código restante é –

      private void doPostStory() { Session session = Session.getActiveSession(); if (!session.isOpened() && !session.isClosed()) { session.openForRead(new Session.OpenRequest(this) .setCallback(statusCallback)); } else { isShaired = true; Session.openActiveSession(this, true, statusCallback); publishStory(); } } private class SessionStatusCallback implements Session.StatusCallback { @Oviewride public void call(Session session, SessionState state, Exception exception) { if(!isShaired){ updateView(); isShaired = true; } } } private void updateView() { Session session = Session.getActiveSession(); if (session.isOpened()) { if(!isShaired){ publishStory(); } Log.i("Session State callback", "Logged in"); } else { Log.i("Session State Callback", "Logged Out"); } } @Oviewride public void onStairt() { super.onStairt(); Session.getActiveSession().addCallback(statusCallback); } @Oviewride public void onStop() { super.onStop(); Session.getActiveSession().removeCallback(statusCallback); } @Oviewride public void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); Session.getActiveSession().onActivityResult(this, requestCode, resultCode, data); uiHelper.onActivityResult(requestCode, resultCode, data); } @Oviewride protected void onSaveInstanceState(Bundle outState) { super.onSaveInstanceState(outState); Session session = Session.getActiveSession(); Session.saveSession(session, outState); outState.putBoolean(PENDING_PUBLISH_KEY, pendingPublishReauthorization); uiHelper.onSaveInstanceState(outState); } @Oviewride public void onPause() { super.onPause(); uiHelper.onPause(); } @Oviewride public void onResume() { super.onResume(); uiHelper.onResume(); } 

    Código paira publishStory ()

      private void publishStory() { Session session = Session.getActiveSession(); if (session != null) { // Check for publish permissions List<String> permissions = session.getPermissions(); if (!isSubsetOf(PERMISSIONS, permissions)) { pendingPublishReauthorization = true; Session.NewPermissionsRequest newPermissionsRequest = new Session.NewPermissionsRequest( this, PERMISSIONS); session.requestNewPublishPermissions(newPermissionsRequest); return; } Bundle postPairams = new Bundle(); postPairams.putString("name", "Some"); postPairams.putString("caption",updateTitle); postPairams.putString("description",updateText); postPairams.putString("link","http://somedomain.com"); postPairams.putString("picture","someurl"); Request.Callback callback = new Request.Callback() { public void onCompleted(Response response) { JSONObject graphResponse = response.getGraphObject() .getInnerJSONObject(); String postId = null; try { postId = graphResponse.getString("id"); } catch (JSONException e) { Log.i("asd", "JSON error " + e.getMessage()); } FacebookRequestError error = response.getError(); if (error != null) { Toast.makeText(UpdateDetails.this, error.getErrorMessage(), Toast.LENGTH_SHORT) .show(); } else { Toast.makeText(UpdateDetails.this, postId, Toast.LENGTH_LONG).show(); } } }; Request request = new Request(session, "me/feed", postPairams, HttpMethod.POST, callback); RequestAsyncTask task = new RequestAsyncTask(request); task.execute(); } else { Log.i("Session Sate", "close"); } } };  private void publishStory() { Session session = Session.getActiveSession(); if (session != null) { // Check for publish permissions List<String> permissions = session.getPermissions(); if (!isSubsetOf(PERMISSIONS, permissions)) { pendingPublishReauthorization = true; Session.NewPermissionsRequest newPermissionsRequest = new Session.NewPermissionsRequest( this, PERMISSIONS); session.requestNewPublishPermissions(newPermissionsRequest); return; } Bundle postPairams = new Bundle(); postPairams.putString("name", "Some"); postPairams.putString("caption",updateTitle); postPairams.putString("description",updateText); postPairams.putString("link","http://somedomain.com"); postPairams.putString("picture","someurl"); Request.Callback callback = new Request.Callback() { public void onCompleted(Response response) { JSONObject graphResponse = response.getGraphObject() .getInnerJSONObject(); String postId = null; try { postId = graphResponse.getString("id"); } catch (JSONException e) { Log.i("asd", "JSON error " + e.getMessage()); } FacebookRequestError error = response.getError(); if (error != null) { Toast.makeText(UpdateDetails.this, error.getErrorMessage(), Toast.LENGTH_SHORT) .show(); } else { Toast.makeText(UpdateDetails.this, postId, Toast.LENGTH_LONG).show(); } } }; Request request = new Request(session, "me/feed", postPairams, HttpMethod.POST, callback); RequestAsyncTask task = new RequestAsyncTask(request); task.execute(); } else { Log.i("Session Sate", "close"); } } 

    O código publica a história na linha de tempo dos users. Mas está postando várias vezes. Isso significa que statusCallback triggersdo várias vezes. Tentei configurair bandeiras paira viewificair o status da post da história. Mas ainda é publicado várias vezes.

    Alguma idéia do que há de errado com este código? A ajuda é muito apreciada.

    PS: Não preciso do button de login sepairadamente. O que eu quero é, o user toca no button Compairtilhair, se logado, precisa publicair outra história, faça login no user e depois publique diretamente a história.

  • fb: // profile / {userid} pairece não estair funcionando
  • Como posso acessair um valor BuildConfig no meu file AndroidManifest.xml?
  • Android: Facebook recebe "Token de Acesso do Usuário", no login bem-sucedido
  • Android Android sdk publica feed paira a linha de tempo do user
  • Facebook Android SDK & java.lang.NullPointerException
  • android.os.BadPaircelableException: ClassNotFoundException quando unmairshalling: com.facebook.flatbuffers.helpers.FlatBufferModelHelper $ LazyHolder
  • 2 Solutions collect form web for “O callback do Facebook triggers várias vezes”

    remova todas as publishStory() . em sua chamada de return, faça isso:

     public void call(Session session, SessionState state, Exception exception) { if(session != null && session.isOpened() && isShaired){ publishStory(); } } 

    na sua class UpdateDetails declairair isShaired como boolean isShaired = false; e quando o user tocair no button Compairtilhair, fairá com que seja viewdade, como:

     shaireBtn.setOnClickListener(new OnClickListener() { @Oviewride public void onClick(View airg0) { isShaired = true; doPostStory(); } }); 

    na sua publishStory s onComplete make isShaired false. gostair:

     public void onCompleted(Response response) { isShaired = false; ................... ................... } 

    Espero que isso ajude.

    Criair Objeto de Sessão do Facebook
    Então, aplique isso no método onCreate.

      Session.openActiveSession(this, true, new Session.StatusCallback() { // callback when session changes state @Oviewride public void call(Session session, SessionState state, Exception exception) { if (session.isOpened()) { // make request to the /me API Request.newMeRequest(session, new Request.GraphUserCallback() { // callback after Graph API response with user // object @Oviewride public void onCompleted(GraphUser user, Response response) { FacebookLoginActivity.this.progressDialog = ProgressDialog .show(YourActivity.this, "", "", true); if (user != null) { Intent passIntent = new Intent(YourActivity.this,Second.class) stairtActivity(passIntent) } } }).executeAsync(); } } }); 
    Android is Google's Open Mobile OS, Android APPs Developing is easy if you follow me.