Get public Twitter tweets API 1.1

This is my first time on the Twitter API

I went through https://dev.twitter.com/docs/api/1.1/get/statuses/user_timeline

I need to get public tweets from https://twitter.com/twitterapi

Link api 1.1 says -

Authentication - Mandatory

And I found something like - AuthTool

I could not combine all these things, since there is no primer.

My main doubts - Is authentication required - should the end user using my application have a twitter account to receive these tweets? (I am planning a mobile application (android) to show some famous public tweets)

  • Where can I find some basic tutorials to get you started?

  • Do I need to transfer tokens with a request? How to get them?

+6
source share
1 answer

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(); } 
+14
source

Source: https://habr.com/ru/post/951614/


All Articles