简体   繁体   中英

Getting “Have you authenticated with Twitter” using Fabric and using Twitter API Client

I'm trying to create a recyclerview of tweets using Fabric. But every time i try to create an TwitterApiClient after authenticating using Fabric all i get is an error with "Have you Authenticated with Twitter?" Here's the code.

    @Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    TwitterAuthConfig authConfig = new TwitterAuthConfig(TWITTER_KEY, TWITTER_SECRET);
    Fabric.with(this, new Twitter(authConfig));
    setContentView(R.layout.activity_main);
    ButterKnife.inject(this);

    TwitterApiClient twitterApiClient = Twitter.getApiClient();
    StatusesService statusesService = twitterApiClient.getStatusesService();
    statusesService.userTimeline(null, "rickygervais", null, null, null, null, null, null, null,
            new Callback<List<Tweet>>() {
                @Override
                public void success(Result<List<Tweet>> listResult) {
                    Log.i(TWITTER_USER_TIMELINE_REQUEST, "Successfully retrieved tweets");
                    feedAdapter.updateItems(listResult.data);
                }

                @Override
                public void failure(TwitterException e) {
                    Log.e(TWITTER_USER_TIMELINE_REQUEST, e.toString());
                }
            });
}

Please tell me i'm being a moron and missing something obvious.

UPDATE

This is the line where i am getting the error message

TwitterApiClient twitterApiClient = Twitter.getApiClient();

The TwitterApiClient requires a Session in order to make Twitter API calls.

Take a look at the documentation here: https://dev.twitter.com/twitter-kit/android/twitter-login

Also, to use guest authentication on android, be sure to update to the latest version of the SDK, 1.3.0.

Your statusesService line is incorrect.

You have

statusesService.userTimeline(null, "rickygervais", null, null, null, null, null, null, null,new Callback<List<Tweet>>() {

Should be

statusesService.userTimeline(session.getId(), null, null, null, null, null, null, null, null, new Callback<List<Tweet>>() {

https://dev.twitter.com/rest/reference/get/statuses/home_timeline

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM