且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Android片段中的Twitter登录/身份验证

更新时间:2023-12-03 20:09:28

我遇到了同样的问题,并以此方式解决了该问题:

I had the same issue and solved it in this way:

  1. 在MainActivity中,配置Twitter并添加onActivityResult函数:

TwitterAuthConfig authConfig =新的TwitterAuthConfig(TWITTER_KEY,TWITTER_SECRET);Fabric.with(this,new Twitter(authConfig));

TwitterAuthConfig authConfig = new TwitterAuthConfig(TWITTER_KEY, TWITTER_SECRET); Fabric.with(this, new Twitter(authConfig));

 @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        FragmentManager fragment = getSupportFragmentManager();
        if (fragment != null) {
       fragment.findFragmentByTag("LoginFragment").onActivityResult(requestCode, resultCode, data);
        }
        else Log.d("Twitter", "fragment is null");
    }

  1. 在LoginFragment中,让您的Twitter按钮的onActivityResult

  1. in your LoginFragment let your twitter button's onActivityResult

@Override

@Override

 public void onActivityResult(int requestCode, int resultCode, Intent data) {
            super.onActivityResult(requestCode, resultCode, data);
            twitterlogin.onActivityResult(requestCode, resultCode, data);
    }

希望这对您很有帮助的问题,如果不是您的话,那么会对其他人有所帮助.

Hope this helps, if not you, then some others with this frustrating issue.