我正在尝试使用搜索来测试Twitter4j
以显示一些推文。目前,它不应该在屏幕上打印任何东西,只是我的日食system.out.printIn
。但它迫使它关闭。
这是我的mainActivity
:
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ConfigurationBuilder cb = new ConfigurationBuilder();
cb.setDebugEnabled(true)
.setOAuthConsumerKey("xxxxxxxxxxxxxxxxxxxxx")
.setOAuthConsumerSecret("xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx")
.setOAuthAccessToken("xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx")
.setOAuthAccessTokenSecret("xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx");
TwitterFactory tf = new TwitterFactory(cb.build());
Twitter twitter = tf.getInstance();
// The factory instance is re-useable and thread safe.
twitter = TwitterFactory.getSingleton();
Query query = new Query("source:twitter4j yusukey");
QueryResult result = null;
try {
result = twitter.search(query);
} catch (TwitterException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
for (Status status : result.getTweets()) {
System.out.println("@" + status.getUser().getScreenName() + ":" + status.getText());
}
}
}
我还使用了twitter4j.properties
debug=true
oauth.consumerKey=xxxxxxxxx
oauth.consumerSecret=bxxxxxxxxxxx
oauth.accessToken=xxxxxxxxxxx
oauth.accessTokenSecret=xxxxxxx
问题是,一旦我打开应用程序,它就会关闭。 logcat
:
11-09 00:15:07.124: E/AndroidRuntime(32369): FATAL EXCEPTION: main
11-09 00:15:07.124: E/AndroidRuntime(32369): java.lang.RuntimeException: Unable to start activity ComponentInfo{xxxxxxxxxxx/MainActivity}: java.lang.IllegalStateException: Authentication credentials are missing. See http://twitter4j.org/en/configuration.html for the detail.
11-09 00:15:07.124: E/AndroidRuntime(32369): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2308)