java:miningthesocialweb
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
java:miningthesocialweb [2014/01/26 00:12] – rlunaro | java:miningthesocialweb [2022/12/02 22:02] (current) – external edit 127.0.0.1 | ||
---|---|---|---|
Line 1: | Line 1: | ||
- | ====== Mining the social web, 2nd edition ====== | + | ====== Mining the social web, 2nd edition |
===== Introduction ===== | ===== Introduction ===== | ||
Line 37: | Line 37: | ||
<code java> | <code java> | ||
+ | public class Examples { | ||
+ | |||
private ConfigurationBuilder cb; | private ConfigurationBuilder cb; | ||
private TwitterFactory tf; | private TwitterFactory tf; | ||
Line 47: | Line 49: | ||
cb.setDebugEnabled(true) | cb.setDebugEnabled(true) | ||
- | .setOAuthConsumerKey(" | + | .setOAuthConsumerKey(" |
- | .setOAuthConsumerSecret(" | + | .setOAuthConsumerSecret(" |
- | .setOAuthAccessToken(" | + | .setOAuthAccessToken(" |
- | .setOAuthAccessTokenSecret(" | + | .setOAuthAccessTokenSecret(" |
| | ||
tf = new TwitterFactory(cb.build()); | tf = new TwitterFactory(cb.build()); | ||
Line 58: | Line 60: | ||
public Twitter getConfiguredTwitter() | public Twitter getConfiguredTwitter() | ||
- | | + | |
- | return twitter; | + | return twitter; |
- | } // sendDirectMessage | + | } // sendDirectMessage |
- | + | ||
- | + | ||
public void getHomeTimeLine() throws TwitterException | public void getHomeTimeLine() throws TwitterException | ||
{ | { | ||
Line 69: | Line 70: | ||
System.out.println( status.getUser().getName() + ": " + status.getText() ); | System.out.println( status.getUser().getName() + ": " + status.getText() ); | ||
} | } | ||
+ | |||
+ | } | ||
</ | </ | ||
+ | === Get world trending topics === | ||
+ | This example displays the trending topics of all the world. The WOEID((Where On Earth ID, Yahoo Service, http:// | ||
+ | |||
+ | |||
+ | <code java> | ||
+ | /** | ||
+ | * Example of page 16, bullet 1.3.3 | ||
+ | */ | ||
+ | public void exploringTrendingTopics() throws TwitterException | ||
+ | { | ||
+ | Trends trends = twitter.trends().getPlaceTrends( 1 ); | ||
+ | | ||
+ | for( Trend trend : trends.getTrends() ) | ||
+ | { | ||
+ | System.out.println( trend.toString() ); | ||
+ | System.out.println( " | ||
+ | System.out.println( " | ||
+ | } | ||
+ | } // exploringTrendingTopics | ||
+ | </ | ||
+ | |||
+ | === Get trending topics by country === | ||
+ | |||
+ | It's possible that not all the trending topics can be consulted. For instance, I've tried with other locations (cities in Spain) and it doesn' | ||
+ | |||
+ | However, you should register in [[http:// | ||
+ | |||
+ | <code java> | ||
+ | /** | ||
+ | * Example of page 16, bullet 1.3.3 | ||
+ | */ | ||
+ | public void exploringTrendingTopics() throws TwitterException, | ||
+ | { | ||
+ | |||
+ | GeoPlanet g = new GeoPlanet(" | ||
+ | PlaceCollection places = g.getPlaces(" | ||
+ | |||
+ | // take only the first ocurrence, | ||
+ | // who is the country | ||
+ | Place spain = places.get(0); | ||
+ | | ||
+ | if( spain == null ) | ||
+ | return; | ||
+ | | ||
+ | Trends trends = twitter.trends().getPlaceTrends( (int) spain.getWoeId() ); | ||
+ | | ||
+ | for( Trend trend : trends.getTrends() ) | ||
+ | { | ||
+ | System.out.println( trend.toString() ); | ||
+ | System.out.println( " | ||
+ | System.out.println( " | ||
+ | } | ||
+ | } // exploringTrendingTopics | ||
+ | </ | ||
===== Oauth in Java: links to investigate ===== | ===== Oauth in Java: links to investigate ===== |
java/miningthesocialweb.txt · Last modified: 2022/12/02 22:02 by 127.0.0.1