Example usage for twitter4j Trends getLocation

List of usage examples for twitter4j Trends getLocation

Introduction

In this page you can find the example usage for twitter4j Trends getLocation.

Prototype

Location getLocation();

Source Link

Document

Returns the location associated with the trends.
This method is effective only with getLocalTrends() method.
i.e.

Usage

From source file:com.mmiagency.knime.nodes.twitter.trends.TwitterTrendsNodeModel.java

License:Open Source License

/**
 * {@inheritDoc}// w  ww . j a v  a2s.co  m
 */
@Override
protected PortObject[] execute(final PortObject[] inObjects, final ExecutionContext exec) throws Exception {

    TrendRowFactory factory = new TrendRowFactory();
    BufferedDataContainer container = exec.createDataContainer(factory.tableSpec());
    int index = 0;

    Twitter twitter = ((TwitterApiConnectionPortObject) inObjects[0]).getTwitterApiConnection().getTwitter();

    Trends trends = twitter.getPlaceTrends(m_config.getWoeid());
    Location location = trends.getLocation();

    for (Trend trend : trends.getTrends()) {
        container.addRowToTable(factory.createRow("" + index++, location, trend));
    }

    container.close();
    return new PortObject[] { container.getTable() };

}

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

/**
 * Usage: java twitter4j.examples.trends.GetPlaceTrends [WOEID=0]
 *
 * @param args message//from  w w w  . j  av  a 2 s. co  m
 */
public static void main(String[] args) {
    try {
        int woeid = args.length > 0 ? Integer.parseInt(args[0]) : 1;
        Twitter twitter = new TwitterFactory().getInstance();
        Trends trends = twitter.getPlaceTrends(woeid);

        System.out.println("Showing trends for " + trends.getLocation().getName());

        for (Trend trend : trends.getTrends()) {
            System.out.println(String.format("%s (tweet_volume: %d)", trend.getName(), trend.getTweetVolume()));
        }

        System.out.println("done.");
        System.exit(0);
    } catch (TwitterException te) {
        te.printStackTrace();
        System.out.println("Failed to get trends: " + te.getMessage());
        System.exit(-1);
    } catch (NumberFormatException nfe) {
        nfe.printStackTrace();
        System.out.println("WOEID must be number");
        System.exit(-1);
    }
}