我的应用程序中的Twitter集成会引发以下非法参数异常
TwitterAuthConfig authConfig = new TwitterAuthConfig(TWITTER_KEY, TWITTER_SECRET);
Fabric.with(this, new Twitter(authConfig), new Crashlytics());
TwitterSession twitterSession = Twitter.getSessionManager().getActiveSession();
Intent intent = new ComposerActivity.Builder(MainActivity.this)
.session(twitterSession)
.darkTheme()
.createIntent();
startActivity(intent);
logcat的:
03-02 14:21:04.183 29087-29087/com.example.admin.twitterintegration E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.admin.twitterintegration, PID: 29087
java.lang.IllegalArgumentException: TwitterSession must not be null
at com.twitter.sdk.android.tweetcomposer.ComposerActivity$Builder.session(ComposerActivity.java:79)
at com.example.admin.twitterintegration.MainActivity$3.onClick(MainActivity.java:105)
at android.view.View.performClick(View.java:4640)
at android.view.View$PerformClick.run(View.java:19425)
at android.os.Handler.handleCallback(Handler.java:733)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:146)
at android.app.ActivityThread.main(ActivityThread.java:5593)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1283)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1099)
at dalvik.system.NativeStart.main(Native Method)
感谢您的帮助。
答案 0 :(得分:1)
在登录按钮中添加回叫
TwitterLoginButton loginButton = (TwitterLoginButton) findViewById(R.id.twitter_login_button);
Callback twitterCallback = new Callback<TwitterSession>() {
@Override
public void success(Result<TwitterSession> result) {
// Do something with result, which provides a TwitterSession for making API calls
}
@Override
public void failure(TwitterException exception) {
// Do something on failure
}
};
loginButton.setCallback(twitterCallback);
在 onActivityResult
中 @Override
protected void onActivityResult(int requestCode, int resultCode, Intent data)
{
super.onActivityResult(requestCode, resultCode, data);
// Pass the activity result to the login button.
loginButton.onActivityResult(requestCode, resultCode, data);
}