Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get Public tweets Twitter API 1.1 [closed]

I am first time on Twitter API's

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

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

The api 1.1 link says-

Authentication - Required

And I found something like - AuthTool

I couldn't connect all these things, as there is no beginner tutorial available.

My Basic doubts - Does Authentication Required means - the end user using my app should have a twitter account to get these tweets? ( I am planing for a mobile app ( android), to show some celebrity's public tweets )

  • Where can I find some basic tutorials to begin with?

  • Do I need some tokens to pass with the request? How to get those?

like image 943
nullUser Avatar asked Aug 13 '13 09:08

nullUser


People also ask

Can you get old tweets from Twitter API?

Twitter Official API has the bother limitation of time constraints, you can't get older tweets than a week.

Do Twitter API keys expire?

Since these keys and tokens do not expire unless regenerated, we suggest that you save them in a secure location, such as a password manager, once you've received your credentials.


1 Answers

I just had a chance to work on a similar issue. Let me help with your questions first.

Does Authentication Required means - the end user using my app should have a twitter account to get these tweets?

No. The end user need not have to sign into his Twitter account to see public feeds. But, you will have to use the consumer key and secret key for the app that you have created in the Twitter developers website.

Do I need some tokens to pass with the request? How to get those?

As I have explained to the previous question, you need to make use of consumer key, consumer secret, access token and access secret.

Here is a little example which I worked on to get public feeds. The below sample will fetch latest 20 public feeds of the user.

Before that you need to import the latest twitter library into your project which is twitter4j 3.0.3 as of now.

And then add the below given code 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();
        }
like image 112
Andro Selva Avatar answered Sep 21 '22 01:09

Andro Selva