取消后再次验证时,Android Twitter套件崩溃

时间:2017-01-14 02:51:52

标签: android twitter-oauth twitter-fabric

我正在使用TwitterKit v2.3.0

com.twitter.sdk.android:twitter:2.3.0@aar

以下是我使用TwitterAuthClient调用Twitter身份验证的方式:

        if (mTwitterAuthClient == null) {
            TwitterAuthConfig authConfig = new TwitterAuthConfig(getString(R.string.twitter_api_key),
                    getString(R.string.twitter_api_secret));
            Fabric.with(getActivity(), new Twitter(authConfig));
        }
        mTwitterAuthClient = new TwitterAuthClient();
        mTwitterAuthClient.authorize(getActivity(), new Callback<TwitterSession>() {
            @Override
            public void success(Result<TwitterSession> result) {
                handleTwitterSession(result.data);
            }

            @Override
            public void failure(TwitterException exception) {
            }
       });

如果我按下登录按钮,然后按回或取消按钮关闭验证屏幕,然后再次按下登录按钮,它会抛出异常而不再显示验证屏幕:

01-13 21:34:40.689 10842-10842/com.ihnel.mclearning W/Twitter: Authorize already in progress
01-13 21:34:40.689 10842-10842/com.ihnel.mclearning 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.binh.auth.fragment.LoginFragment.loginWithTwitter(LoginFragment.java:157)
                                                                   at com.binh.auth.databinding.AuthFragmentLoginBinding$OnClickListenerImpl2.onClick(AuthFragmentLoginBinding.java:273)
                                                                   at android.view.View.performClick(View.java:5198)
                                                                   at android.view.View$PerformClick.run(View.java:21147)
                                                                   at android.os.Handler.handleCallback(Handler.java:739)
                                                                   at android.os.Handler.dispatchMessage(Handler.java:95)
                                                                   at android.os.Looper.loop(Looper.java:148)
                                                                   at android.app.ActivityThread.main(ActivityThread.java:5417)
                                                                   at java.lang.reflect.Method.invoke(Native Method)
                                                                   at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
                                                                   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)

我检查了Twitter核心源代码,它保留了AuthState的静态实例,虽然我重新创建了TwitterAuthClient的新实例,但它永远不会更新。 有人知道如何绕过这个例外吗?

1 个答案:

答案 0 :(得分:3)

在Twitter社区中找到类似的帖子:https://twittercommunity.com/t/getting-authorization-error-when-cancelling-from-twitter-authorization-using-fabric-sdk/31341/10

当我在我的活动中实施onActivityResult方法时,问题就出现了,如下所示:

@Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        final TwitterAuthClient twitterAuthClient = new TwitterAuthClient();
        if(twitterAuthClient.getRequestCode()==requestCode) {
            twitterAuthClient.onActivityResult(requestCode, resultCode, data);
        }
    }

但是,这只是他们所说的解决方法。我希望我们能得到最终的解决方案。