Android Twitter Fabric的成功方法未被调用

时间:2015-10-23 09:43:11

标签: android twitter

我正在使用Twitter Fabric并在片段中实现。 我onActivityCreated片段的回调方法我写了这段代码......

authConfig = new TwitterAuthConfig(TWITTER_KEY, TWITTER_SECRET);
        Fabric.with(getActivity(), new Twitter(authConfig));
        mTwitterLoginButton = (TwitterLoginButton) getActivity().findViewById(R.id.twitter_login_button);
        mTwitterLoginButton.setCallback(new Callback<TwitterSession>() {
            @Override
            public void success(Result<TwitterSession> result) {
                // Do something with result, which provides a TwitterSession for making API calls
                Toast.makeText(getActivity(), "Successfully Loggedin", Toast.LENGTH_SHORT).show();

                TwitterSession session = result.data;
                //TwitterSession session = Twitter.getSessionManager().getActiveSession();
                long uid = session.getUserId();
                String usrname = session.getUserName();
                TwitterAuthToken authToken = session.getAuthToken();
                String token = authToken.token;
                String secret = authToken.secret;
                Log.d("TAG", "token :" + token + ", secret :" + secret);
                Log.d("TAG", "uid :" + uid + ", usrname :" + usrname);
            }

            @Override
            public void failure(TwitterException exception) {
                // Do something on failure
                Toast.makeText(getActivity(), ""+exception, Toast.LENGTH_SHORT).show();
            }
        });

在Activity的onActivityResult中,我编写了这段代码......

@Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);

        // Pass the activity result to the fragment, which will then pass the result to the login
        // button.
        Fragment myStocks = getSupportFragmentManager().findFragmentByTag(FragmentIdentifier.getString(FragmentIdentifier.MY_STOCKS.getId()));
        if (myStocks != null) {
            myStocks.onActivityResult(requestCode, resultCode, data);
        }
    }

当我第一次点击Twitter登录按钮时,Twitter登录页面正在启动,当我点击授权应用程序然后返回片段而不调用成功回调。

当我点击Twitter登录按钮第二次或下次时,将调用失败回调。

这是失败日志...

10-23 06:31:44.588    5173-5173/com.stockal.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:4780)
            at android.view.View$PerformClick.run(View.java:19866)
            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:5254)
            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:903)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)

build.gradle -

buildscript {
    repositories {
        maven { url 'https://maven.fabric.io/public' }
    }

    dependencies {
        classpath 'io.fabric.tools:gradle:1.+'
    }
}

apply plugin: 'com.android.application'
apply plugin: 'io.fabric'

repositories {
    maven { url 'https://maven.fabric.io/public' }
}

AndroidManifest.xml -

<meta-data
            android:name="io.fabric.ApiKey"
            android:value="<KEY>" />

请帮我解决这个问题。我在代码中遗漏了什么吗?

提前致谢

0 个答案:

没有答案