Search in sources :

Example 1 with TwitterAuthConfig

use of com.twitter.sdk.android.core.TwitterAuthConfig in project quickstart-android by firebase.

the class TwitterLoginActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    // Configure Twitter SDK
    TwitterAuthConfig authConfig = new TwitterAuthConfig(getString(R.string.twitter_consumer_key), getString(R.string.twitter_consumer_secret));
    Fabric.with(this, new Twitter(authConfig));
    // Inflate layout (must be done after Twitter is configured)
    setContentView(R.layout.activity_twitter);
    // Views
    mStatusTextView = (TextView) findViewById(R.id.status);
    mDetailTextView = (TextView) findViewById(R.id.detail);
    findViewById(R.id.button_twitter_signout).setOnClickListener(this);
    // [START initialize_auth]
    // Initialize Firebase Auth
    mAuth = FirebaseAuth.getInstance();
    // [END initialize_auth]
    // [START auth_state_listener]
    mAuthListener = new FirebaseAuth.AuthStateListener() {

        @Override
        public void onAuthStateChanged(@NonNull FirebaseAuth firebaseAuth) {
            FirebaseUser user = firebaseAuth.getCurrentUser();
            if (user != null) {
                // User is signed in
                Log.d(TAG, "onAuthStateChanged:signed_in:" + user.getUid());
            } else {
                // User is signed out
                Log.d(TAG, "onAuthStateChanged:signed_out");
            }
            // [START_EXCLUDE]
            updateUI(user);
        // [END_EXCLUDE]
        }
    };
    // [END auth_state_listener]
    // [START initialize_twitter_login]
    mLoginButton = (TwitterLoginButton) findViewById(R.id.button_twitter_login);
    mLoginButton.setCallback(new Callback<TwitterSession>() {

        @Override
        public void success(Result<TwitterSession> result) {
            Log.d(TAG, "twitterLogin:success" + result);
            handleTwitterSession(result.data);
        }

        @Override
        public void failure(TwitterException exception) {
            Log.w(TAG, "twitterLogin:failure", exception);
            updateUI(null);
        }
    });
// [END initialize_twitter_login]
}
Also used : TwitterSession(com.twitter.sdk.android.core.TwitterSession) Twitter(com.twitter.sdk.android.Twitter) TwitterAuthConfig(com.twitter.sdk.android.core.TwitterAuthConfig) FirebaseUser(com.google.firebase.auth.FirebaseUser) TwitterException(com.twitter.sdk.android.core.TwitterException) FirebaseAuth(com.google.firebase.auth.FirebaseAuth)

Example 2 with TwitterAuthConfig

use of com.twitter.sdk.android.core.TwitterAuthConfig in project FirebaseAuth-Android by jirawatee.

the class TwitterLoginActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    // Configure Twitter SDK
    TwitterAuthConfig authConfig = new TwitterAuthConfig(getString(R.string.twitter_consumer_key), getString(R.string.twitter_consumer_secret));
    Fabric.with(this, new Twitter(authConfig));
    // Inflate layout (must be done after Twitter is configured)
    setContentView(R.layout.activity_twitter);
    mImageView = findViewById(R.id.logo);
    mTextViewProfile = findViewById(R.id.profile);
    findViewById(R.id.button_twitter_signout).setOnClickListener(this);
    mAuth = FirebaseAuth.getInstance();
    mAuthListener = new FirebaseAuth.AuthStateListener() {

        @Override
        public void onAuthStateChanged(@NonNull FirebaseAuth firebaseAuth) {
            FirebaseUser user = firebaseAuth.getCurrentUser();
            if (user != null) {
                Log.d(TAG, "onAuthStateChanged:signed_in:" + user.getUid());
            } else {
                Log.d(TAG, "onAuthStateChanged:signed_out");
            }
            updateUI(user);
        }
    };
    // initialize_twitter_login
    mLoginButton = findViewById(R.id.button_twitter_login);
    mLoginButton.setCallback(new Callback<TwitterSession>() {

        @Override
        public void success(Result<TwitterSession> result) {
            Log.d(TAG, "twitterLogin:success" + result);
            handleTwitterSession(result.data);
        }

        @Override
        public void failure(TwitterException exception) {
            Log.w(TAG, "twitterLogin:failure", exception);
            updateUI(null);
        }
    });
}
Also used : TwitterSession(com.twitter.sdk.android.core.TwitterSession) Twitter(com.twitter.sdk.android.Twitter) TwitterAuthConfig(com.twitter.sdk.android.core.TwitterAuthConfig) FirebaseUser(com.google.firebase.auth.FirebaseUser) TwitterException(com.twitter.sdk.android.core.TwitterException) FirebaseAuth(com.google.firebase.auth.FirebaseAuth)

Example 3 with TwitterAuthConfig

use of com.twitter.sdk.android.core.TwitterAuthConfig in project ServiceStack.Java by ServiceStack.

the class LoginActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    Fabric.with(this, new Twitter(new TwitterAuthConfig(getString(R.string.twitter_key), getString(R.string.twitter_secret))));
    setContentView(R.layout.login);
    Toolbar toolbar = (Toolbar) findViewById(R.id.loginToolbar);
    setSupportActionBar(toolbar);
    getSupportActionBar().setHomeButtonEnabled(true);
    getSupportActionBar().setDisplayShowTitleEnabled(true);
    progressBar = (ProgressBar) findViewById(R.id.progressBar);
    txtStatus = (TextView) findViewById(R.id.txtStatus);
    UiHelpers.setStatus(txtStatus, "");
    // see this max value coming back here, we animale towards that value
    animation = ObjectAnimator.ofInt(progressBar, "progress", 0, 500);
    animation.setRepeatMode(ValueAnimator.REVERSE);
    animation.setRepeatCount(100);
    animation.setDuration(1500);
    animation.setInterpolator(new FastOutLinearInInterpolator());
    LoginActivity activity = this;
    ImageButton btnTwitter = (ImageButton) findViewById(R.id.btnTwitter);
    twitterAuth = new TwitterAuthClient();
    btnTwitter.setOnClickListener(view -> {
        startProgressBar();
        twitterAuth.authorize(activity, new Callback<TwitterSession>() {

            @Override
            public void success(Result<TwitterSession> result) {
                UiHelpers.setStatus(txtStatus, "Local twitter sign-in successful, signing into server...");
                TwitterSession session = result.data;
                App.get().getServiceClient().postAsync(new dtos.Authenticate().setProvider("twitter").setAccessToken(session.getAuthToken().token).setAccessTokenSecret(session.getAuthToken().secret).setRememberMe(true), r -> {
                    UiHelpers.setStatus(txtStatus, "Server twitter sign-in successful, opening chat...");
                    App.get().saveTwitterAccessToken(session.getAuthToken());
                    Intent intent = new Intent(activity, MainActivity.class);
                    stopProgressBar();
                    startActivity(intent);
                }, error -> {
                    UiHelpers.setStatusError(txtStatus, "Server twitter sign-in failed", error);
                    stopProgressBar();
                });
            }

            @Override
            public void failure(TwitterException exception) {
                exception.printStackTrace();
                stopProgressBar();
            }
        });
    });
    facebookCallback = CallbackManager.Factory.create();
    LoginManager.getInstance().registerCallback(facebookCallback, new FacebookCallback<LoginResult>() {

        @Override
        public void onSuccess(LoginResult loginResult) {
            UiHelpers.setStatus(txtStatus, "Local facebook sign-in successful, signing into server...");
            App.get().getServiceClient().postAsync(new dtos.Authenticate().setProvider("facebook").setAccessToken(loginResult.getAccessToken().getToken()).setRememberMe(true), r -> {
                UiHelpers.setStatus(txtStatus, "Server facebook sign-in successful, opening chat...");
                Intent intent = new Intent(activity, MainActivity.class);
                stopProgressBar();
                startActivity(intent);
            }, error -> {
                UiHelpers.setStatusError(txtStatus, "Server facebook sign-in failed", error);
                stopProgressBar();
            });
        }

        @Override
        public void onCancel() {
            stopProgressBar();
        }

        @Override
        public void onError(FacebookException exception) {
            Log.e(exception);
            stopProgressBar();
        }
    });
    ImageButton btnFacebook = (ImageButton) findViewById(R.id.btnFacebook);
    btnFacebook.setOnClickListener(view -> {
        startProgressBar();
        LoginManager.getInstance().logInWithReadPermissions(this, Arrays.asList("email"));
    });
    ImageButton btnAnon = (ImageButton) findViewById(R.id.btnAnon);
    btnAnon.setOnClickListener(view -> {
        UiHelpers.setStatus(txtStatus, "Opening chat as guest...");
        startGuestChatActivity(App.get().getServiceClient());
    });
    dtos.Authenticate authDto = App.get().getSavedAccessToken();
    if (authDto != null) {
        UiHelpers.setStatus(txtStatus, "Signing in with saved " + authDto.getProvider() + " AccessToken...");
        App.get().getServiceClient().postAsync(authDto, r -> {
            Intent intent = new Intent(activity, MainActivity.class);
            stopProgressBar();
            startActivity(intent);
        }, error -> {
            UiHelpers.setStatusError(txtStatus, "Error logging into " + authDto.getProvider() + " using Saved AccessToken", error);
            stopProgressBar();
        });
    }
}
Also used : Result(com.twitter.sdk.android.core.Result) ImageButton(android.widget.ImageButton) Text(org.w3c.dom.Text) Arrays(java.util.Arrays) Bundle(android.os.Bundle) ProgressBar(android.widget.ProgressBar) Intent(android.content.Intent) Twitter(com.twitter.sdk.android.Twitter) TwitterAuthConfig(com.twitter.sdk.android.core.TwitterAuthConfig) TwitterException(com.twitter.sdk.android.core.TwitterException) View(android.view.View) AccessToken(com.facebook.AccessToken) FacebookException(com.facebook.FacebookException) ObjectAnimator(android.animation.ObjectAnimator) LoginResult(com.facebook.login.LoginResult) AppCompatActivity(android.support.v7.app.AppCompatActivity) FacebookCallback(com.facebook.FacebookCallback) CallbackManager(com.facebook.CallbackManager) LoginManager(com.facebook.login.LoginManager) TwitterAuthClient(com.twitter.sdk.android.core.identity.TwitterAuthClient) TextView(android.widget.TextView) Callback(com.twitter.sdk.android.core.Callback) AndroidServiceClient(net.servicestack.android.AndroidServiceClient) FastOutLinearInInterpolator(android.support.v4.view.animation.FastOutLinearInInterpolator) Toolbar(android.support.v7.widget.Toolbar) Fabric(io.fabric.sdk.android.Fabric) Log(net.servicestack.client.Log) ValueAnimator(android.animation.ValueAnimator) TwitterSession(com.twitter.sdk.android.core.TwitterSession) TwitterSession(com.twitter.sdk.android.core.TwitterSession) LoginResult(com.facebook.login.LoginResult) FastOutLinearInInterpolator(android.support.v4.view.animation.FastOutLinearInInterpolator) Twitter(com.twitter.sdk.android.Twitter) TwitterAuthConfig(com.twitter.sdk.android.core.TwitterAuthConfig) Intent(android.content.Intent) TwitterAuthClient(com.twitter.sdk.android.core.identity.TwitterAuthClient) ImageButton(android.widget.ImageButton) FacebookException(com.facebook.FacebookException) TwitterException(com.twitter.sdk.android.core.TwitterException) Toolbar(android.support.v7.widget.Toolbar)

Example 4 with TwitterAuthConfig

use of com.twitter.sdk.android.core.TwitterAuthConfig in project ServiceStack.Java by ServiceStack.

the class LoginButtonsActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    Fabric.with(this, new Twitter(new TwitterAuthConfig(getString(R.string.twitter_key), getString(R.string.twitter_secret))));
    setContentView(R.layout.login_buttons);
    Toolbar toolbar = (Toolbar) findViewById(R.id.loginToolbar);
    setSupportActionBar(toolbar);
    getSupportActionBar().setHomeButtonEnabled(true);
    getSupportActionBar().setDisplayShowTitleEnabled(true);
    progressBar = (ProgressBar) findViewById(R.id.progressBar);
    txtStatus = (TextView) findViewById(R.id.txtStatus);
    UiHelpers.setStatus(txtStatus, "");
    // see this max value coming back here, we animale towards that value
    animation = ObjectAnimator.ofInt(progressBar, "progress", 0, 500);
    animation.setRepeatMode(ValueAnimator.REVERSE);
    animation.setRepeatCount(100);
    animation.setDuration(1500);
    animation.setInterpolator(new FastOutLinearInInterpolator());
    LoginButtonsActivity activity = this;
    btnTwitterLogin = (TwitterLoginButton) findViewById(R.id.btnTwitterLogin);
    btnTwitterLogin.setCallback(new Callback<TwitterSession>() {

        @Override
        public void success(Result<TwitterSession> result) {
            startProgressBar();
            UiHelpers.setStatus(txtStatus, "Local twitter sign-in successful, signing into server...");
            TwitterSession session = result.data;
            App.get().getServiceClient().postAsync(new dtos.Authenticate().setProvider("twitter").setAccessToken(session.getAuthToken().token).setAccessTokenSecret(session.getAuthToken().secret).setRememberMe(true), r -> {
                UiHelpers.setStatus(txtStatus, "Server twitter sign-in successful, opening chat...");
                App.get().saveTwitterAccessToken(session.getAuthToken());
                Intent intent = new Intent(activity, MainActivity.class);
                stopProgressBar();
                startActivity(intent);
            }, error -> {
                UiHelpers.setStatusError(txtStatus, "Server twitter sign-in failed", error);
                stopProgressBar();
            });
        }

        @Override
        public void failure(TwitterException exception) {
            Log.e(exception);
            stopProgressBar();
        }
    });
    facebookCallback = CallbackManager.Factory.create();
    btnFacebookLogin = (LoginButton) findViewById(R.id.btnFacebookLogin);
    btnFacebookLogin.setReadPermissions("email");
    btnFacebookLogin.registerCallback(facebookCallback, new FacebookCallback<LoginResult>() {

        @Override
        public void onSuccess(LoginResult loginResult) {
            UiHelpers.setStatus(txtStatus, "Local facebook sign-in successful, signing into server...");
            App.get().getServiceClient().postAsync(new dtos.Authenticate().setProvider("facebook").setAccessToken(loginResult.getAccessToken().getToken()).setRememberMe(true), r -> {
                UiHelpers.setStatus(txtStatus, "Server facebook sign-in successful, opening chat...");
                Intent intent = new Intent(activity, MainActivity.class);
                stopProgressBar();
                startActivity(intent);
            }, error -> {
                UiHelpers.setStatusError(txtStatus, "Server facebook sign-in failed", error);
                stopProgressBar();
            });
        }

        @Override
        public void onCancel() {
            stopProgressBar();
        }

        @Override
        public void onError(FacebookException exception) {
            Log.e(exception);
            stopProgressBar();
        }
    });
    Button btnGuestLogin = (Button) findViewById(R.id.btnGuestLogin);
    btnGuestLogin.setOnClickListener(view -> {
        UiHelpers.setStatus(txtStatus, "Opening chat as guest...");
        startGuestChatActivity(App.get().getServiceClient());
    });
    dtos.Authenticate authDto = App.get().getSavedAccessToken();
    if (authDto != null) {
        UiHelpers.setStatus(txtStatus, "Signing in with saved " + authDto.getProvider() + " AccessToken...");
        App.get().getServiceClient().postAsync(authDto, r -> {
            Intent intent = new Intent(activity, MainActivity.class);
            stopProgressBar();
            startActivity(intent);
        }, error -> {
            UiHelpers.setStatusError(txtStatus, "Error logging into " + authDto.getProvider() + " using Saved AccessToken", error);
            stopProgressBar();
        });
    }
}
Also used : Result(com.twitter.sdk.android.core.Result) Bundle(android.os.Bundle) ProgressBar(android.widget.ProgressBar) Intent(android.content.Intent) Twitter(com.twitter.sdk.android.Twitter) TwitterAuthConfig(com.twitter.sdk.android.core.TwitterAuthConfig) TwitterException(com.twitter.sdk.android.core.TwitterException) View(android.view.View) Button(android.widget.Button) LoginButton(com.facebook.login.widget.LoginButton) AccessToken(com.facebook.AccessToken) FacebookException(com.facebook.FacebookException) ObjectAnimator(android.animation.ObjectAnimator) LoginResult(com.facebook.login.LoginResult) AppCompatActivity(android.support.v7.app.AppCompatActivity) FacebookCallback(com.facebook.FacebookCallback) CallbackManager(com.facebook.CallbackManager) TextView(android.widget.TextView) Callback(com.twitter.sdk.android.core.Callback) AndroidServiceClient(net.servicestack.android.AndroidServiceClient) FastOutLinearInInterpolator(android.support.v4.view.animation.FastOutLinearInInterpolator) Toolbar(android.support.v7.widget.Toolbar) TwitterLoginButton(com.twitter.sdk.android.core.identity.TwitterLoginButton) Fabric(io.fabric.sdk.android.Fabric) Log(net.servicestack.client.Log) Activity(android.app.Activity) ValueAnimator(android.animation.ValueAnimator) TwitterSession(com.twitter.sdk.android.core.TwitterSession) TwitterSession(com.twitter.sdk.android.core.TwitterSession) LoginResult(com.facebook.login.LoginResult) FastOutLinearInInterpolator(android.support.v4.view.animation.FastOutLinearInInterpolator) Twitter(com.twitter.sdk.android.Twitter) TwitterAuthConfig(com.twitter.sdk.android.core.TwitterAuthConfig) Intent(android.content.Intent) Button(android.widget.Button) LoginButton(com.facebook.login.widget.LoginButton) TwitterLoginButton(com.twitter.sdk.android.core.identity.TwitterLoginButton) FacebookException(com.facebook.FacebookException) TwitterException(com.twitter.sdk.android.core.TwitterException) Toolbar(android.support.v7.widget.Toolbar)

Example 5 with TwitterAuthConfig

use of com.twitter.sdk.android.core.TwitterAuthConfig in project EffectiveAndroid by rallat.

the class EffectiveAndroidApplication method setUpFabric.

public void setUpFabric() {
    TwitterAuthConfig authConfig = new TwitterAuthConfig(BuildConfig.CONSUMER_KEY, BuildConfig.CONSUMER_SECRET);
    Fabric.with(this, new TwitterCore(authConfig));
}
Also used : TwitterCore(com.twitter.sdk.android.core.TwitterCore) TwitterAuthConfig(com.twitter.sdk.android.core.TwitterAuthConfig)

Aggregations

TwitterAuthConfig (com.twitter.sdk.android.core.TwitterAuthConfig)6 TwitterException (com.twitter.sdk.android.core.TwitterException)5 TwitterSession (com.twitter.sdk.android.core.TwitterSession)5 Twitter (com.twitter.sdk.android.Twitter)4 ObjectAnimator (android.animation.ObjectAnimator)2 ValueAnimator (android.animation.ValueAnimator)2 Intent (android.content.Intent)2 Bundle (android.os.Bundle)2 FastOutLinearInInterpolator (android.support.v4.view.animation.FastOutLinearInInterpolator)2 AppCompatActivity (android.support.v7.app.AppCompatActivity)2 Toolbar (android.support.v7.widget.Toolbar)2 View (android.view.View)2 ProgressBar (android.widget.ProgressBar)2 TextView (android.widget.TextView)2 AccessToken (com.facebook.AccessToken)2 CallbackManager (com.facebook.CallbackManager)2 FacebookCallback (com.facebook.FacebookCallback)2 FacebookException (com.facebook.FacebookException)2 LoginResult (com.facebook.login.LoginResult)2 FirebaseAuth (com.google.firebase.auth.FirebaseAuth)2