Using Twitter4j Daily Trends?

java, twitter

Solution

getPlaceTrends(int woeid)

Returns the top 10 trending topics for a specific WOEID, if trending information is available for it.

woeid - The Yahoo! Where On Earth ID of the location to return trending information for. Global information is available by using 1 as the WOEID.

You can get the WOEID's of different locations with the code below

Twitter twitter = new TwitterFactory().getInstance();
ResponseList<Location> locations;
locations = twitter.getAvailableTrends();
System.out.println("Showing available trends");
for (Location location : locations) {
    System.out.println(location.getName() + " (woeid:" + location.getWoeid() + ")");
}

And then, you can get the present trends of a specific location using it's WOEID like below

Trends trends = twitter.getPlaceTrends(2295414);
for (int i = 0; i < trends.getTrends().length; i++) {
    System.out.println(trends.getTrends()[i].getName());
}

Problem

i've been working on a small program where I want to read in trending twitter topics and store them in a database. Currently I am using the twitter4j getDailyTrends() method, but getting strange results. The code I currently have is: ``` Twitter twitter = new TwitterFactory().getInstance(); ResponseList<Trends> dailyTrends; dailyTrends = twitter.getDailyTrends(); System.out.println(); // Print the trends. for (Trends trends : dailyTrends) { System.out.println("As of : " + trends.getAsOf()); for (Trend trend : trends.getTrends()) { System.out.println(" " + trend.getName()); } } ``` However, when the program runs, it shows the same list of trends 24 times. I have tried running the program on different days, however the list is always identical, no matter what day I run the program on. I have also tried passing the getDailyTrends() method the current date and achieved the same results. Would appreciate any help with this, it's driving me crazy. :) EDIT: The result set I keep getting is displaying the twitter trends from 25.04.2012. And no matter when I run the program, or what date I give it - I get these same results. EDIT2: OK so this has been bugging me all day, I eventually found the example code provided by twitter4j themselves for reading trends. I ran their code instead of mine, and I am having the same issue. The trends are a few weeks old, and never change. Has anyone actually managed to get this method working before?

Original source