Twitter Kit Android - constantly asks for authentication


have a twitter login file which is pretty boiler plate:

public class TwitterLogin extends AppCompatActivity {
TwitterAuthClient client;

protected void onCreate(Bundle savedInstanceState) {
    TwitterConfig config = new TwitterConfig.Builder(this)
            .logger(new DefaultLogger(Log.DEBUG))
            .twitterAuthConfig(new TwitterAuthConfig("key", "key"))
    client = new TwitterAuthClient();
    //make the call to login
    client.authorize(this, new Callback<TwitterSession>() {
        public void success(Result<TwitterSession> result) {
            Toast.makeText(getApplicationContext(), "Login worked", Toast.LENGTH_LONG).show();

        public void failure(TwitterException e) {
            Toast.makeText(getApplicationContext(), "Login failed", Toast.LENGTH_LONG).show();
    startActivity(new Intent(TwitterLogin.this,MainFeedScreen.class));


protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    //this method call is necessary to get our callback to get called.
    client.onActivityResult(requestCode, resultCode, data);


This seems to work fine.

However, I also have an AsyncTask class that is meant to go off and get a users home timeline:

public class TwitterRequests extends AsyncTask<String,String,JSONObject> {`
  TwitterApiClient twitterApiClient;
       StatusesService statusesService;
        private MainFeedScreen mainAct;
        private ProgressDialog progressDialog;
       private List<Tweet> tweetList; 
   public TwitterRequests(View v, MainFeedScreen mainAct){
        twitterApiClient = TwitterCore.getInstance().getApiClient();
        statusesService = twitterApiClient.getStatusesService();
        this.mainAct = mainAct;
        this.progressDialog = new ProgressDialog(v.getContext());

protected JSONObject doInBackground(String... params) {
    Call<List<Tweet>> call  = statusesService.homeTimeline(20,null,null,false,false,true,true);
    call.enqueue(new Callback<List<Tweet>>() {
        public void onResponse(Call<List<Tweet>> call, Response<List<Tweet>> response) {
            Log.d("Twitter","In on response");

              //            tweetList = response.body();

        public void onFailure(Call<List<Tweet>> call, Throwable t) {
            Log.d("Twitter","in failure");


    return new JSONObject();

protected void onPreExecute() {

protected void onPostExecute(JSONObject jsonObject) {
    mainAct.setRedditAdapter(new TwitterAdapter(tweetList));

In another activity I make a new instance of TwitterRequest() and execute it.

Whenever I do this, I am redirected to a webview for Twitter where I must authorise myself again. If i press authorise it redirects me to my homescreen. If i press the button again it does the same thing.

Any ideas why I keep needing to reauthorise my app?

many thanks.


You can check to see if user has already been authenticated and skip the login.

if (TwitterCore.getInstance().getSessionManager().getActiveSession() != null) {
    // do something else


Thanks for the response, but this doesn’t really help. The code tells me that login was successful but still redirects me to login again as soon as i tap twitter again.


I also have same problem with here but I can’t use this solution, the problem is I use TwitterAuthClient only when I want to share to Twitter so there’s no logout button. If I use your solution, the same account will stuck forever there.
For information, I only set Read and Write permission without DM.
This is what I found on internet and other discussion:
there are 2 different type: Authorize and Authenticate.
Authorize will always ask for permission, and Authenticate only ask once. but in TwitterAuthClient only have Authorize(). how can I access Authenticate in Android?