Fabric: TwitterSession always null

故事扮演 提交于 2019-12-12 04:17:54

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!