I'm trying to create a small website which takes user's twitter username and retrieve the basic information from it like: screen name, created date, number of followers, etc... and display it. But I couldn't find a new helpful working tutorial or example of how to work with twitter API. Can someone please recommend something for me or just give some instructions of how should I start and work please? I prefer it to be done with Java or PHP.
Also I have a problem, when creating my application access key in twitter, I can't create the access token! the button is not shown! how can I solve this?
You Can use below code-
import twitter4j.Query;
import twitter4j.QueryResult;
import twitter4j.Status;
import twitter4j.Twitter;
import twitter4j.TwitterException;
import twitter4j.TwitterFactory;
import twitter4j.conf.ConfigurationBuilder;
public class TwitterSearch {
private static final String CATEGORY = "Mobile";
private static final String SOURCE = "Twitter";
public static void main(String ...args) throws TwitterException, IOException
{
ConfigurationBuilder cb = new ConfigurationBuilder();
cb.setDebugEnabled(true)
.setOAuthConsumerKey(TwitterConfig.OATH_CONSUMER_KEY)
.setOAuthConsumerSecret(TwitterConfig.OATH_CONSUMER_SECRET)
.setOAuthAccessToken(TwitterConfig.OATH_ACCESS_TOKEN)
.setOAuthAccessTokenSecret(TwitterConfig.OATH_ACCESS_TOKEN_SECRET);
TwitterFactory tf = new TwitterFactory(cb.build());
Twitter twitter = tf.getInstance();
System.out.println("Product to be searched " + args[0]);
Query query = new Query(args[0]);
query.setLang("en");
query.setLocale("en_IN");
query.setCount(100);
QueryResult result = twitter.search(query);
System.out.println("Output File "+ args[1]);
System.out.println(result.getTweets());
for(Status tweet : result.getTweets())
{
System.out.println(tweet.getText());
}
}
}
result.getTweets() return a List, and you can iterate over that list and can print tweet.getText() to print tweet.
Use this maven dependency-
<dependency><groupId>org.twitter4j</groupId><artifactId>twitter4j-core</artifactId><version>[4.0,)</version></dependency>
Refer below link for keys-