facebook login callback fires multiple times

前端 未结 2 1791
半阙折子戏
半阙折子戏 2021-02-06 10:28

My app is having Share button to share story on users timeline. What I\'m doing is, user taps on Share button, if user session is not present app forces to Logi

相关标签:
2条回答
  • 2021-02-06 10:36

    remove all the publishStory() calling. in your callback do this:

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

    in your UpdateDetails class declare isShared as boolean isShared = false; and when user tap on share button make it true, like:

    shareBtn.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View arg0) {
            isShared = true;
            doPostStory();                              
        }
    });
    

    in your publishStorys onComplete make isShared false. like:

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

    hope this will help.

    0 讨论(0)
  • 2021-02-06 10:43

    Create Facebook Session Object
    Then Just Apply This in onCreate Method.

     Session.openActiveSession(this, true, new Session.StatusCallback() {
    
            // callback when session changes state
            @Override
            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
                                @Override
                                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)
                                       startActivity(passIntent)
                                    }
                                }
                            }).executeAsync();
    
                }
            }
        });
    
    0 讨论(0)
提交回复
热议问题