Twitter login without TwitterLoginButton

2019-06-18 16:21发布

问题:

Is there any built-in way to initiate a login without using the TwitterLoginButton. All examples that I could find use a TwitterLoginButton.

回答1:

This works.

TwitterAuthClient mTwitterAuthClient= new TwitterAuthClient();
mTwitterAuthClient.authorize(activity, new Callback<TwitterSession>() {

    @Override
    public void success(Result<TwitterSession> twitterSessionResult) {
        // Success
    }

    @Override
    public void failure(TwitterException e) {
        e.printStackTrace();
    }
});

@Override
protected void onActivityResult(int requestCode, int responseCode, Intent intent) {
    mTwitterAuthClient.onActivityResult(requestCode, responseCode, intent);
}