java:miningthesocialweb
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revision | |||
java:miningthesocialweb [2022/12/02 21:02] – external edit 127.0.0.1 | java:miningthesocialweb [2024/10/05 17:12] (current) – removed rlunaro | ||
---|---|---|---|
Line 1: | Line 1: | ||
- | ====== Mining the social web, 2nd edition in Java ====== | ||
- | ===== Introduction ===== | ||
- | |||
- | I'm reading the book " | ||
- | |||
- | [[http:// | ||
- | |||
- | The book gives a deep insight of how to exploit data from social websites, and it's a topic I am quite interested. However, the recipes are in python, but I want to make my own recipes in java. This page is for register my achievements (if any) and notes, because there are tons of link that might be interested or worth reading. | ||
- | |||
- | ===== Twitter ===== | ||
- | |||
- | The first chapter of the book deals with Twitter. To make my own java excursion into the topic, [[#Learning path for Twitter|I' | ||
- | |||
- | ==== Pick the libraries ==== | ||
- | |||
- | Ive selected those libraries for my access to Twitter with java: | ||
- | |||
- | |||
- | * [[http:// | ||
- | * [[https:// | ||
- | * http:// | ||
- | |||
- | **Why this libraries?? | ||
- | |||
- | You may also need one library for the service [[http:// | ||
- | |||
- | ==== My first code ==== | ||
- | |||
- | It is very hard to program with Twitter4J or even Scribe because there is no documentation available, so most of the time you will be trying to guess what's the object/ | ||
- | |||
- | Because I was so lost in the beginning, I've decided to follow simple goals at a time, mimicking the different steps of the book. Here are my steps: | ||
- | |||
- | === Basic Object === | ||
- | |||
- | I've created a basic to hold all my examples: | ||
- | |||
- | <code java> | ||
- | public class Examples { | ||
- | |||
- | private ConfigurationBuilder cb; | ||
- | private TwitterFactory tf; | ||
- | private Twitter twitter; | ||
- | |||
- | public Examples() | ||
- | { | ||
- | // creating of the Twitter object | ||
- | cb = new ConfigurationBuilder(); | ||
- | |||
- | cb.setDebugEnabled(true) | ||
- | .setOAuthConsumerKey(" | ||
- | .setOAuthConsumerSecret(" | ||
- | .setOAuthAccessToken(" | ||
- | .setOAuthAccessTokenSecret(" | ||
- | | ||
- | tf = new TwitterFactory(cb.build()); | ||
- | twitter = tf.getInstance(); | ||
- | |||
- | } | ||
- | |||
- | public Twitter getConfiguredTwitter() | ||
- | { | ||
- | return twitter; | ||
- | } // sendDirectMessage | ||
- | | ||
- | public void getHomeTimeLine() throws TwitterException | ||
- | { | ||
- | List< | ||
- | for( Status status : statuses ) | ||
- | 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 ===== | ||
- | |||
- | |||
- | * [[https:// | ||
- | * [[http:// | ||
- | * [[http:// | ||
- | |||
- | ===== Oauth libraries in java ===== | ||
- | |||
- | [[https:// | ||
- | |||
- | I've tried the example of the Twitter library for this library and it doesn' | ||
- | |||
- | [[http:// | ||
- | |||
- | [[http:// | ||
- | |||
- | [[https:// | ||
- | |||
- | An example to see it working: | ||
- | |||
- | [[http:// | ||
- | |||
- | Other libraries and links: | ||
- | |||
- | * [[http:// | ||
- | * [[http:// | ||
- | * [[http:// | ||
- | * [[https:// | ||
- | * [[https:// | ||
- | * [[http:// | ||
- | |||
- | |||
- | ===== Learning path for Twitter ===== | ||
- | |||
- | Apart from the book, which I encourage to read even you are not keen on python, these are my readings: | ||
- | |||
- | |||
- | [[http:// | ||
- | |||
- | If you are like me, probably OAuth is a technology that doesn' | ||
- | |||
- | |||
- | |||
- | |||
- | ===== Facebook ===== | ||
- | |||
- | http:// | ||
- | |||
- | RestFB is a simple and flexible Facebook Graph API and Old REST API client written in Java. | ||
- | It is open source software released under the terms of the MIT License. |
java/miningthesocialweb.1670014949.txt.gz · Last modified: 2022/12/02 21:02 by 127.0.0.1