我正在尝试使用Twitter4j库从Twitter用户时间线检索推文,并将它们集成到Android应用程序中。我已经完成了获取消费者密钥/访问令牌的所有具体步骤,然后按照以下方式在我的代码中设置它们。
ConfigurationBuilder cb = new ConfigurationBuilder();
cb.setDebugEnabled(true)
.setOAuthConsumerKey(CONSUMER_KEY)
.setOAuthConsumerSecret(CONSUMER_SECRET)
.setOAuthAccessToken(ACCESS_TOKEN)
.setOAuthAccessTokenSecret(ACCESS_SECRET)
.setApplicationOnlyAuthEnabled(true);
Configuration config = cb.build();
tf = new TwitterFactory(config);
twitter = tf.getInstance();
bearerToken = twitter.getOAuth2Token();
twitter.setOAuth2Token(bearerToken);;
// The factory instance is re-useable and thread safe.
twitter = tf.getSingleton();
statuses = twitter.getUserTimeline(name);
但是,当我运行应用程序时,出现以下错误:
Caused by: java.lang.IllegalStateException: Authentication credentials are missing. See http://twitter4j.org/en/configuration.html for details
at twitter4j.TwitterBaseImpl.ensureAuthorizationEnabled(TwitterBaseImpl.java:186)
at twitter4j.TwitterImpl.get(TwitterImpl.java:1554)
at twitter4j.TwitterImpl.getUserTimeline(TwitterImpl.java:129)
at twitter4j.TwitterImpl.getUserTimeline(TwitterImpl.java:150)
注意:我已就此主题搜索了许多类似的问题,到目前为止没有成功。
任何帮助都会非常感谢大家!