I had the opportunity to work on a similar problem. Let me first help with your questions.
Is authentication required - the end user using my application must have a twitter account to receive these tweets?
No. End users do not need to log in to their Twitter account to view public channels. But you will need to use the client key and secret key for the application that you created on the Twitter developers website.
Do I need to use tokens to transmit with the request? How to get them?
As I explained to the previous question, you need to use the consumer key, consumer secret, access token and access secret.
Here is a small example that I worked on to get public channels. In the example below, the last 20 public channels of the user will be selected.
Before that, you need to import the latest twitter library into your project, which is now twitter4j 3.0.3.
And then add the code below to your project and should be done.
ConfigurationBuilder cb = new ConfigurationBuilder(); cb.setDebugEnabled(true) .setOAuthConsumerKey("B***************Q") .setOAuthConsumerSecret( "l*********************************o") .setOAuthAccessToken( "1*******************************X") .setOAuthAccessTokenSecret( "1***************************c"); TwitterFactory tf = new TwitterFactory(cb.build()); Twitter twitter = tf.getInstance(); try { List<Status> statuses; String user; user = "replace with the user name of your choice"; statuses = twitter.getUserTimeline(user); Log.i("Status Count", statuses.size() + " Feeds"); for (int i = 0; i < statuses.size(); i++) { Status status = statuses.get(i); Log.i("Tweet Count " + (i + 1), status.getText() + "\n\n"); } } catch (TwitterException te) { te.printStackTrace(); }
source share