Java源码示例:com.twitter.sdk.android.Twitter

示例1
public void logout() {
    if (AccessToken.getCurrentAccessToken() != null) {
        LoginManager.getInstance().logOut();
        Logger.printInfo(LOG_TAG, "Loged out from facebook");
    }
    if (Twitter.getSessionManager().getActiveSession() != null) {
        Twitter.getSessionManager().clearActiveSession();
        Twitter.logOut();
        Logger.printInfo(LOG_TAG, "Loged out from twitter");
    }
    if (VKSdk.isLoggedIn()) {
        VKSdk.logout();
        Logger.printInfo(LOG_TAG, "Loged out from vk");
    }
    Prefs.remove(SyncMaster.GLOBAL_TOKEN);
    userProfile = new UserProfile();
}
 
示例2
public void initUserProfile(final IOperationFinishWithDataCallback profileFetched, boolean isForceUpdate) {
    if (userProfile != null && !isForceUpdate) {
        profileFetched.operationFinished(userProfile);
    } else if (!isLogedIn()) {
        userProfile = new UserProfile();
        profileFetched.operationFinished(userProfile);
    } else {
        if (AccessToken.getCurrentAccessToken() != null) {
            fetchFacebookUserData(profileFetched);
        } else if (Twitter.getSessionManager().getActiveSession() != null) {
            fetchTwitterUserData(profileFetched);
        } else if (VKSdk.isLoggedIn()) {
            fetchVkUserData(profileFetched);
        }
    }
}
 
示例3
private void fetchTwitterUserData(final IOperationFinishWithDataCallback profileFetched) {
    TwitterSession session =
            Twitter.getSessionManager().getActiveSession();
    Twitter.getApiClient(session).getAccountService()
            .verifyCredentials(true, false, new Callback<User>() {
                @Override
                public void success(Result<User> userResult) {
                    User user = userResult.data;
                    userProfile = new UserProfile();
                    userProfile.setName(user.screenName);
                    String profileImage = user.profileImageUrlHttps;
                    profileImage = profileImage.replace("_normal", "");
                    userProfile.setProfileImageUrl(profileImage);
                    profileFetched.operationFinished(userProfile);
                }

                @Override
                public void failure(TwitterException e) {

                }
            });
}
 
示例4
private void setUpSignOut() {
    final TextView bt = (TextView) findViewById(R.id.deactivate_accounts);
    bt.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Twitter.getSessionManager().clearActiveSession();
            Digits.getSessionManager().clearActiveSession();
            SessionRecorder.recordSessionInactive("About: accounts deactivated");
            Answers.getInstance().logLogin(new LoginEvent().putMethod("Twitter").putSuccess(false));
            Answers.getInstance().logLogin(new LoginEvent().putMethod("Digits").putSuccess(false));

            Toast.makeText(getApplicationContext(), "All accounts are cleared",
                    Toast.LENGTH_SHORT).show();
        }
    });
}
 
示例5
public String getLoginType() {
    if (Prefs.getString(SyncMaster.GLOBAL_TOKEN, null) != null) {
        return SyncMaster.TYPE_GLOBAL;
    } else if (AccessToken.getCurrentAccessToken() != null)
        return SyncMaster.TYPE_FB;
    else if (Twitter.getSessionManager().getActiveSession() != null) {
        return SyncMaster.TYPE_TWITTER;
    } else
        return SyncMaster.TYPE_VK;
}
 
示例6
public String getToken() {
    if (Prefs.getString(SyncMaster.GLOBAL_TOKEN, null) != null) {
        return Prefs.getString(SyncMaster.GLOBAL_TOKEN, null);
    } else if (AccessToken.getCurrentAccessToken() != null)
        return AccessToken.getCurrentAccessToken().getToken();
    else if (Twitter.getSessionManager().getActiveSession() != null) {
        TwitterSession session = Twitter.getSessionManager().getActiveSession();
        TwitterAuthToken authToken = session.getAuthToken();
        return authToken.token;
    } else
        return VKAccessToken.currentToken().accessToken;
}
 
示例7
public String getSecret() {
    if (Twitter.getSessionManager().getActiveSession() != null) {
        TwitterSession session = Twitter.getSessionManager().getActiveSession();
        TwitterAuthToken authToken = session.getAuthToken();
        return authToken.secret;
    }
    return "";
}
 
示例8
/**
 * setup Twitter, Crashlytics
 */
protected void setupFabric() {
    TwitterAuthConfig authConfig = new TwitterAuthConfig(
            BuildConfig.TWITTER_API_KEY,
            BuildConfig.TWITTER_API_SECRET);
    Fabric.with(mApp, new Twitter(authConfig), new Crashlytics());
}
 
示例9
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    TwitterSession session = Twitter.getSessionManager().getActiveSession();
    if (session != null) {
        startActivity(MainActivity.createIntent(this));
        finish();
    }

    setContentView(R.layout.activity_login);

    ButterKnife.bind(this);

    mLoginButton.setCallback(new Callback<TwitterSession>() {
        @Override
        public void success(Result<TwitterSession> result) {
            Timber.d("Authorization succeeded");
            Timber.d("name: %s", result.data.getUserName());
            mLoginButton.setVisibility(View.GONE);

            startActivity(MainActivity.createIntent(LoginActivity.this));
            finish();
        }

        @Override
        public void failure(TwitterException e) {
            Timber.e(e, e.getMessage());
        }
    });
}
 
示例10
private void initFabric() {
    // Only initialize Fabric if Twitter integration is fully configured
    TwitterConfig.init(context);
    TwitterConfig config = TwitterConfig.getInstance();
    if (config.isConfigured()) {
        logger.info("Event hashtag is " + config.getEventHashtag() + ".  Initializing Fabric.");
        TwitterAuthConfig auth = new TwitterAuthConfig(config.getApiKey(), config.getApiSecret());
        Fabric.with(context, new Twitter(auth));
    }
    else {
        logger.info("Twitter integration is not configured; Fabric not initialized");
    }
}
 
示例11
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    final Session activeSession = SessionRecorder.recordInitialSessionState(
            Twitter.getSessionManager().getActiveSession(),
            Digits.getSessionManager().getActiveSession()
    );

    if (activeSession != null) {
        startThemeActivity();
    } else {
        startLoginActivity();
    }
}
 
示例12
@Override
public void onCreate() {
    super.onCreate();
    singleton = this;
    extractAvenir();
    authConfig
            = new TwitterAuthConfig(BuildConfig.CONSUMER_KEY, BuildConfig.CONSUMER_SECRET);
    Fabric.with(this, new Crashlytics(), new Digits(), new Twitter(authConfig), new MoPub());

    Crashlytics.setBool(CRASHLYTICS_KEY_CRASHES, areCrashesEnabled());
}
 
示例13
public void performSignIn(Context context) {
  TwitterAuthConfig authConfig = new TwitterAuthConfig(mTwitterApiKey, mTwitterSecreteKey);
  Fabric.with(context, new Twitter(authConfig));
  mAuthClient.authorize(mActivity, mCallback);
}
 
示例14
private void initTwitter() {
    TwitterAuthConfig authConfig = new TwitterAuthConfig(Config.TWITTER_CONSUMER_KEY, Config.TWITTER_CONSUMER_SECRET);
    Fabric.with(UpodsApplication.getContext(), new Twitter(authConfig));
}
 
示例15
public boolean isLogedIn() {
    return AccessToken.getCurrentAccessToken() != null || Twitter.getSessionManager().getActiveSession() != null || VKSdk.isLoggedIn();
}
 
示例16
@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]
}
 
示例17
private void signOut() {
    mAuth.signOut();
    Twitter.logOut();

    updateUI(null);
}