Mauricio
Mauricio

Reputation: 1

how to log in with my twitter account in an android application with twiterkit

I am making an android application using java as the programming language. The app in its main window has 3 buttons to be able to log in with the account of any of its social networks (facebook, twitter and gmail respectively),I implemented this in a new activity. I was developing the button to be able to log in with my twitter account using twitter kit but when I click I get the message = "Login fail" and it does not take into consideration the previous code. I hope you can help me. Greetings

my code:

public class loggin extends AppCompatActivity {
    //variable twitter
    TwitterLoginButton login;
    
    //other variables
    TextView recoveruser,recoverpassword;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        Twitter.initialize(this);
      
        login = (TwitterLoginButton) findViewById(R.id.twitter_login_button);

       
        //configuración para twitter:
        login.setCallback(new Callback<TwitterSession>() {
            @Override
            public void success(Result<TwitterSession> result) {
                TwitterSession session =TwitterCore.getInstance().getSessionManager().getActiveSession();
                TwitterAuthToken authToken = session.getAuthToken();
                String token = authToken.token;
                String secret = authToken.secret;

                if (token != null ) {
                    //Log.d(TAG, "twitter token" + token);
                    Toast.makeText(getApplicationContext(),"twitter token" + token,Toast.LENGTH_LONG).show();
                }

                if (secret != null ) {
                    Toast.makeText(getApplicationContext(), "twitter secret" + secret,Toast.LENGTH_LONG).show();
                   // Log.d(TAG, "twitter secret" + secret);
                }

                String userName=session.getUserName();
                Intent intent= new Intent(loggin.this,MainActivity.class);
                intent.putExtra("username",userName);
                startActivity(intent);

            }

            @Override
            public void failure(TwitterException exception) {
                Toast.makeText(getApplicationContext(),"Login fail",Toast.LENGTH_LONG).show();
            }
        });


    }
    @Override
    public void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        login.onActivityResult(requestCode, resultCode, data);
       
       }
    }

Upvotes: 0

Views: 112

Answers (0)

Related Questions