Skip to content
This repository has been archived by the owner on May 17, 2019. It is now read-only.

Twitter kit constantly asking me to "authorise app" #87

Open
MatthewJamesBoyle opened this issue Jun 1, 2017 · 2 comments
Open

Twitter kit constantly asking me to "authorise app" #87

MatthewJamesBoyle opened this issue Jun 1, 2017 · 2 comments

Comments

@MatthewJamesBoyle
Copy link

I have a twitter login file which is pretty boiler plate:


public class TwitterLogin extends AppCompatActivity {

    TwitterAuthClient client;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_twitter_login);
        TwitterConfig config = new TwitterConfig.Builder(this)
                .logger(new DefaultLogger(Log.DEBUG))
                .twitterAuthConfig(new TwitterAuthConfig("key", "key"))
                .debug(true)
                .build();
        Twitter.initialize(config);
        client = new TwitterAuthClient();
        //make the call to login
        client.authorize(this, new Callback<TwitterSession>() {
            @Override
            public void success(Result<TwitterSession> result) {
                //feedback
                Toast.makeText(getApplicationContext(), "Login worked", Toast.LENGTH_LONG).show();
            }

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


    }

    @Override
    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());

    }

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

//            tweetList = response.body();
            }

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



            }
        });


        return new JSONObject();
    }

    @Override
    protected void onPreExecute() {
        super.onPreExecute();
        progressDialog.show();
    }

    @Override
    protected void onPostExecute(JSONObject jsonObject) {
        super.onPostExecute(jsonObject);
        mainAct.setRedditAdapter(new TwitterAdapter(tweetList));
        mainAct.getmRecyclerView().setAdapter(mainAct.getRedditAdapter());
        progressDialog.hide();
    }
}

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.

After hours of frustration and no mention in the docs, im starting to think this a bug.

@jaychang0917
Copy link

Same issue, when i click the button to login again, it will redirect to authorisation page even I sign in successfully before. What I expect is the success(Result<TwitterSession> result) should be called instead redirecting to authorisation page if I logged in previously.

@adamc01
Copy link
Contributor

adamc01 commented Jul 24, 2017

As a workaround to #90 you can check if the user is already logged in or not:

if (TwitterCore.getInstance().getSessionManager().getActiveSession() != null) {
    // User already logged-in
} else {
  // Call authorize
}

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants