我正在使用TwitterKit
compile('com.twitter.sdk.android:twitter:2.2.0@aar') {
transitive = true;
}
以下是我使用TwitterAuthClient调用Twitter身份验证的方法:
loginButtonTwitter = (TwitterLoginButton) findViewById(R.id.twitter_login_button);
loginButtonTwitter.setCallback(new Callback<TwitterSession>() {
@Override
public void success(Result<TwitterSession> result) {
mType = 3;
// The TwitterSession is also available through:
// Twitter.getInstance().core.getSessionManager().getActiveSession()
session = result.data;
// TODO: Remove toast and use the TwitterSession's userID
// with your app's user model
// String msg = "@" + session.getUserName() + " logged in! (#" + session.getUserId() + ")";
// Toast.makeText(getApplicationContext(), msg, Toast.LENGTH_LONG).show();
LOGD(":: Name ::", session.getUserName());
getUserData();
}
@Override
public void failure(TwitterException exception) {
Log.d("TwitterKit", "Login with Twitter failure", exception);
mType = 0;
}
});
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
loginButtonTwitter.onActivityResult(requestCode, resultCode, data);
}
如果我按下登录按钮,然后按回或取消按钮关闭验证屏幕,然后再次按下登录按钮,它会抛出异常而不再显示验证屏幕:
01-17 12:01:06.216 3316-3316/com.app E/Twitter: Authorization completed with an error
com.twitter.sdk.android.core.TwitterAuthException: Authorize failed.
at com.twitter.sdk.android.core.identity.TwitterAuthClient.handleAuthorize(TwitterAuthClient.java:110)
at com.twitter.sdk.android.core.identity.TwitterAuthClient.authorize(TwitterAuthClient.java:101)
at com.twitter.sdk.android.core.identity.TwitterLoginButton$LoginClickListener.onClick(TwitterLoginButton.java:161)
at android.view.View.performClick(View.java:4788)
at android.view.View$PerformClick.run(View.java:19923)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5382)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:928)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:723)