I'm using Fabric and I want to check, from my android application if the user is connected on the Twitter application or in the browser. So I have to check the active session. For that I use this code:
TwitterSession twitterSession = TwitterCore.getInstance().getSessionManager().getActiveSession();
And this is how Fabric added the code in the onCreate
of the MainActivity
:
TwitterAuthConfig authConfig = new TwitterAuthConfig(twitterKey, twitterSecretKey);
Fabric.with(this, new Twitter(authConfig));
Is Fabric initialized correctly?
Why I'm always getting null in the twitterSession
? Even if I test it in the onCreate
of the MainActivity
?
rTry this
iv_tweet.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
twitterAuthClient.authorize(LoginActivity.this, new Callback<TwitterSession>() {
@Override
public void success(Result<TwitterSession> twitterSessionResult) {
Log.e("success1", "success1");
final TwitterSession session = Twitter.getSessionManager().getActiveSession();
}
@Override
public void failure(TwitterException e) {
Toast.makeText(LoginActivity.this, e.getMessage(), Toast.LENGTH_SHORT).show();
}
});
}
});
and in onActivity result
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == TwitterAuthConfig.DEFAULT_AUTH_REQUEST_CODE) {
twitterAuthClient.onActivityResult(requestCode, resultCode, data);
}
}
If that doesn't meet your need please comment below
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.