问题
I want to check if the user is already connected on Twitter in order to post tweets from my android application. Using Fabric, I check the TwitterSession
via this code:
TwitterCore twitterCore = TwitterCore.getInstance();
TwitterSession twitterSession = twitterCore.getSessionManager().getActiveSession();
return (twitterSession != null && !twitterSession.getAuthToken().isExpired());
The problem is that the twitterSession
is always null, even if I'm connected on the Twitter application.
How can I solve this problem?
回答1:
you have to initialize it in onCreate firstly. I was used twitter digits and it initilize somthing like that :
TwitterAuthConfig authConfig = new TwitterAuthConfig(TWITTER_KEY, TWITTER_SECRET);
Fabric.with(this, new Answers(), new TwitterCore(authConfig), new Digits());
StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder()
.detectAll()
.penaltyLog()
.build());
StrictMode.setVmPolicy(new StrictMode.VmPolicy.Builder()
.detectAll()
.penaltyLog()
.build());
final Digits digits = new Digits.Builder()
.withDigitsEventLogger(new AnswersLogger())
.build();
i think look at this page
来源:https://stackoverflow.com/questions/43074159/fabric-twittersession-always-null