Development of Twitter Application #6 - Trends

1,654 views

Published on

This series of slides describes how to develop a twitter application.
This slide describes getting trends information from Twitter using Twitter4J.

Published in: Technology, Education
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
1,654
On SlideShare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
19
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Development of Twitter Application #6 - Trends

  1. 1. Linked Data &Semantic WebTechnologyDevelopment ofTwitter ApplicationsPart 6. TrendsDr. Myungjin Lee
  2. 2. Linked Data & Semantic Web TechnologyTrends API• Trends REST API– to explore whats trending on Twitter– Trends are determined by an algorithm and aretailored for you based on who you follow and yourlocation.2
  3. 3. Linked Data & Semantic Web TechnologyREST API related to Trends3Resource DescriptionGETtrends/placeReturns the top 10 trending topics for a specific WOEID, iftrending information is available for it. The response is an arrayof "trend" objects that encode the name of the trending topic, thequery parameter that can be used to search for the topic onTwitter Search, and the Twitter Search URL....GETtrends/availableReturns the locations that Twitter has trending topic informationfor. The response is an array of "locations" that encode thelocations WOEID and some other human-readable informationsuch as a canonical name and country the location belongs in. AWOEID is a Yahoo! Where On Earth ID.GETtrends/closestReturns the locations that Twitter has trending topic informationfor, closest to a specified location. The response is an array of"locations" that encode the locations WOEID and some otherhuman-readable information such as a canonical name andcountry the location belongs in. A WOEID is a Yahoo...
  4. 4. Linked Data & Semantic Web TechnologyGET trends/available• Resource URL– https://api.twitter.com/1.1/trends/available.json• Other Information– Requests per rate limit window: 15/user, 15/app– Authentication: Required– Response• The response is an array of "locations" that encode thelocations WOEID and some other human-readableinformation.• A WOEID is a Yahoo! Where On Earth ID.– API Version: v1.14
  5. 5. Linked Data & Semantic Web TechnologyTwitter4J Classes for Trends• TrendsResources Interface– Methods• ResponseList<Location> getAvailableTrends()• Trends getPlaceTrends(int woeid)• Location Interface– Methods• java.lang.String getCountryCode()• java.lang.String getCountryName()• java.lang.String getName()• int getPlaceCode()• java.lang.String getPlaceName()• java.lang.String getURL()• int getWoeid()• Trends Interface– Methods• Location getLocation()• java.util.Date getTrendAt()• Trend[] getTrends()• Trend Interface– A data interface representing Trend.– Methods• java.lang.String getName()• java.lang.String getURL()5
  6. 6. Linked Data & Semantic Web TechnologyGetting Locations for Available Trends1. import twitter4j.Location;2. import twitter4j.ResponseList;3. import twitter4j.Twitter;4. import twitter4j.TwitterException;5. import twitter4j.TwitterFactory;6. public class TwitterTrends {7. Twitter twitter = null;8. public TwitterTrends() {9. this.twitter = TwitterFactory.getSingleton();10. this.twitter.setOAuthConsumer(TwitterAccessToken.consumerKey,11. TwitterAccessToken.consumerSecret);12. this.twitter.setOAuthAccessToken(TwitterAccessToken.loadAccessToken());13. }14. public static void main(String args[]) throws TwitterException {15. TwitterTrends tt = new TwitterTrends();16. ResponseList<Location> locations = tt.twitter.getAvailableTrends();17. for (int i = 0; i < locations.size(); i++) {18. Location location = locations.get(i);19. System.out.println(location.getName() + ", "20. + location.getCountryName() + ": " + location.getWoeid());21. }22. }23. }6
  7. 7. Linked Data & Semantic Web TechnologyGET trends/place• Resource URL– https://api.twitter.com/1.1/trends/place.json• Parameters• Other Information– Requests per rate limit window: 15/user, 15/app– Authentication: Required– API Version: v1.1idrequiredThe Yahoo! Where On Earth ID of the location to return trendinginformation for. Global information is available by using 1 as the WOEID.excludeoptionalSetting this equal to hashtags will remove all hashtags from the trends list.7
  8. 8. Linked Data & Semantic Web TechnologyGetting Trends1. public static void main(String args[]) throws TwitterException {2. TwitterTrends tt = new TwitterTrends();3. Trends trends = tt.twitter.getPlaceTrends(1);4. Trend[] trend = trends.getTrends();5. for(int i = 0; i < trend.length; i++) {6. System.out.println(i + ". " + trend[i].getName());7. }8. }8

×