android - TwitterSession 不能为空
问题描述
我已使用此代码撰写推文,但收到 TweitterSession 错误。在这里,我附上了日志,请帮我解决这个问题。
//在应用程序类中
TwitterConfig config = new TwitterConfig.Builder(this)
.logger(new DefaultLogger(Log.DEBUG))//enable logging when app is in debug mode
.twitterAuthConfig(new TwitterAuthConfig("ConsumerKey", "ConsumerSecret"))//pass the created app Consumer KEY and Secret also called API Key and Secret
.debug(true)//enable debug mode
.build();
//finally initialize twitter with created configs
Twitter.initialize(config);
//OnClick按钮
final TwitterSession session = TwitterCore.getInstance().getSessionManager().getActiveSession();
final Intent intent = new ComposerActivity.Builder(MainActivity.this)
.session(session)
.text("Love where you work")
.hashtags("#twitter")
.createIntent();
startActivity(intent);
日志::
TwitterSession must not be null
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2450)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2510)
at android.app.ActivityThread.-wrap11(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1363)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5461)
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)
Caused by: java.lang.IllegalArgumentException: TwitterSession must not be null
at com.twitter.sdk.android.tweetcomposer.ComposerActivity$Builder.session(ComposerActivity.java:95)
at com.example.inextrix.twittereazydemo.MainActivity.onCreate(MainActivity.java:51)
at android.app.Activity.performCreate(Activity.java:6251)
解决方案
推荐阅读
- vue.js - 如何处理多参数查询的 Apollo 缓存更新(例如表格数据)
- python - 有效地生成字符串的所有可能子字符串的列表
- ubuntu - 如何获取存储桶中的前 100 个文件
- bash - Keepalived运行bash脚本退出代码问题
- javascript - Javascript生成的输入字段未发布
- python - 如何使用处理时间过长的巨大匹配关键字文件?
- php - 文件夹中随机播放的视频播放列表
- angular - Ionic 4,离子滑动垂直滚动不起作用
- properties - Gremlin 更新现有属性
- python-3.x - ValueError: `validation_data` 应该是一个元组 `(val_x, val_y, val_sample_weight)` 或 `(val_x, val_y)`。找到:<__main__.Generator 对象在>