0

我正在尝试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)
4

0 回答 0