Top 10 Twitter Trending Topics using JAVA twitter4j API

Hi friends,

Today we are going to find out the Top 10 Worldwide Trending Topics on Twitter with the help of twitter4j Java API.

The step by step process can be depicted in below picture. It shows the step by step algorithm which you can use in order to show top 10 Worldwide Trending Twitter Topics.

Twitter Trends
Twitter Trends

 

Now, what do these trending topics mean?

The simple answer is it shows what people are talking about on twitter. It kind of gives you some idea about the topics that are getting discussed over “mentioned” places. In our case, this mentioned place is the entire world i.e. we are going to retrieve the trending topics across the world.

For that we are using the following code.

There are few things that we should know about the above code. Those are as follows.

  • Consumer Key, Consumer Secret, Access Token and Access Token Secret are the parameters we get after creating our own twitter app at https://www.apps.twitter.com
  • getPlaceTrends() method in line number 25 expects the Yahoo Place Id. In this case, we are passing it as 1 which means we want to find the trends worldwide. Similarly, you can pass any Place Id to get the trending topics for that particular place.
  • The counter that we are using in line number 28 is for getting the top 10 trending topics.

Once I ran above code, I got the following output.It shows the trending topics at that particular time.

Program Output
Program Output

And for verification, I went to my twitter account and saw the latest trending topics on twitter.com. Following is the screenshot of the trending topics on twitter.com

Actual Trends
Actual Trends

As you can see from above two screenshots, both my program and twitter.com is giving the same results.

This completes our twitter4j implementation of trending topics.

Thanks for having a read.

Published by milindjagre

I founded my blog www.milindjagre.co four years ago and am currently working as a Data Scientist Analyst at the Ford Motor Company. I graduated from the University of Connecticut pursuing Master of Science in Business Analytics and Project Management. I am working hard and learning a lot of new things in the field of Data Science. I am a strong believer of constant and directional efforts keeping the teamwork at the highest priority. Please reach out to me at milindjagre@gmail.com for further information. Cheers!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: