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?
Twitter Official API has the bother limitation of time constraints, you can't get older tweets than a week.
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.
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();
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With