Example usage for twitter4j Location getWoeid

List of usage examples for twitter4j Location getWoeid

Introduction

In this page you can find the example usage for twitter4j Location getWoeid.

Prototype

int getWoeid();

Source Link

Usage

From source file:twitter4j.examples.trends.GetAvailableTrends.java

License:Apache License

/**
 * Usage: java twitter4j.examples.trends.GetAvailableTrends
 *
 * @param args message/*w  ww  .j av  a  2s.  c  o m*/
 */
public static void main(String[] args) {
    try {
        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() + ")");
        }
        System.out.println("done.");
        System.exit(0);
    } catch (TwitterException te) {
        te.printStackTrace();
        System.out.println("Failed to get trends: " + te.getMessage());
        System.exit(-1);
    }
}

From source file:wap.twitter.model.TwitterUtility.java

public List<Trend> getTrends(GeoLocation loc) throws TwitterException {
    TwitterFactory tf = config();/*w  w w.j a v  a 2 s  .  c  o  m*/
    Twitter twitter = tf.getInstance();
    List<Trend> tds = new ArrayList<Trend>();
    ResponseList<Location> locations;
    locations = twitter.getClosestTrends(loc);
    for (Location location : locations) {
        Trends trends = twitter.getPlaceTrends(location.getWoeid());
        for (int i = 0; i < trends.getTrends().length; i++) {
            if (i == 10) {
                break;
            }
            tds.add(trends.getTrends()[i]);
        }
    }
    return tds;
}

From source file:wap.twitter.model.TwitterUtility.java

private static Integer getTrendLocationId(String locationName) {

    int idTrendLocation = 0;

    try {//www  .  j  ava 2 s. com

        ConfigurationBuilder cb = new ConfigurationBuilder();
        cb.setDebugEnabled(true).setOAuthConsumerKey("yourConsumerKey")
                .setOAuthConsumerSecret("yourConsumerSecret").setOAuthAccessToken("yourOauthToken")
                .setOAuthAccessTokenSecret("yourOauthTokenSecret");

        TwitterFactory tf = new TwitterFactory(cb.build());
        Twitter twitter = tf.getInstance();

        ResponseList<Location> locations;
        locations = twitter.getAvailableTrends();

        for (Location location : locations) {
            if (location.getName().toLowerCase().equals(locationName.toLowerCase())) {
                idTrendLocation = location.getWoeid();
                break;
            }
        }

        if (idTrendLocation > 0) {
            return idTrendLocation;
        }

        return null;

    } catch (TwitterException te) {
        te.printStackTrace();
        System.out.println("Failed to get trends: " + te.getMessage());
        return null;
    }

}