User Tools

Site Tools


java:miningthesocialweb

Differences

This shows you the differences between two versions of the page.


Previous revision
java:miningthesocialweb [2022/12/02 22:02] (current) – external edit 127.0.0.1
Line 1: Line 1:
 +====== Mining the social web, 2nd edition in Java ======
  
 +===== Introduction =====
 +
 +I'm reading the book "Mining the social web, 2nd edition". Look how cute it is: 
 +
 +[[http://shop.oreilly.com/product/0636920030195.do|{{http://akamaicovers.oreilly.com/images/0636920030195/cat.gif}}]]
 +
 +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've read some things]].
 +
 +==== Pick the libraries ====
 +
 +Ive selected those libraries for my access to Twitter with java:
 +
 +
 +   * [[http://twitter4j.org/]]
 +   * [[https://github.com/fernandezpablo85/scribe-java|Scribe]]
 +   * http://www.winterwell.com/software/jgeoplanet/
 +
 +**Why this libraries??** The process I've followed is to watch some projects in GitHub I was interested in and follow the projects: if there were messages, add one point. Then I've looked to the readme page of the project, and I was pleased to to read in the case of Scribe that this library has plenty of examples of a vast collection of social networks, so I thought it was nice to have half of the work done. 
 +
 +You may also need one library for the service [[http://developer.yahoo.com/geo/geoplanet/|Yahoo Geoplanet]] because it's needed to locate the trending topics by location id.
 +
 +==== 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/method you need to instantiate to go to the next step. 
 +
 +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("HERE-GOES-YOUR-CONSUMER-KEY")
 +        .setOAuthConsumerSecret("HERE-GOES-YOUR-CONSUMER-SECRET")
 +        .setOAuthAccessToken("HERE-GOES-YOUR-ACCESS-TOKEN")
 +        .setOAuthAccessTokenSecret("HERE-GOES-YOUR-ACCESS-TOKEN-SECRET");
 +          
 +        tf = new TwitterFactory(cb.build());
 +        twitter = tf.getInstance();
 +
 + }
 +
 + public Twitter getConfiguredTwitter()
 +  {
 +      return twitter;
 +  } // sendDirectMessage
 +  
 + public void getHomeTimeLine() throws TwitterException
 + {
 +   List<Status> statuses = twitter.getHomeTimeline();
 +   for( Status status : statuses )
 +   System.out.println( status.getUser().getName() + ": " + status.getText() );
 + }
 +
 +}
 +</code>
 +
 +
 +=== Get world trending topics ===
 +
 +This example displays the trending topics of all the world. The WOEID((Where On Earth ID, Yahoo Service, http://developer.yahoo.com/geo/geoplanet/)) of the whole world is 1. 
 +
 +
 +<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( "Trend: " + trend.getName() );
 +        System.out.println( "  Url: " + trend.getURL() );
 +    }
 +} // exploringTrendingTopics
 +</code>
 +
 +=== 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't work. It does work searching for the trending topics of Spain, for instance. Would work searching for little countries like Andorra or Cittá del Vaticano?
 +
 +However, you should register in [[http://developer.yahoo.com/geo/geoplanet/|Yahoo! Geoplanet]] to get the ID for Spain or other country.
 +
 +<code java>
 +/**
 + * Example of page 16, bullet 1.3.3
 + */
 +public void exploringTrendingTopics() throws TwitterException, GeoPlanetException
 +{
 +
 +    GeoPlanet g = new GeoPlanet("PUT-HERE-YOUR-PROJECT-CONSUMER-KEY");
 +    PlaceCollection places = g.getPlaces("Spain");
 +
 +    // 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( "Trend: " + trend.getName() );
 +        System.out.println( "  Url: " + trend.getURL() );
 +    }
 +} // exploringTrendingTopics
 +</code>
 +
 +===== Oauth in Java: links to investigate =====
 +
 +
 +    * [[https://www.github.com/twitter/hbc|Official Twitter Library for Java]] (232 followers)
 +    * [[http://twitter4j.org/|Twitter4J, another Twitter Library for Java]] and [[http://www.wigwag.com/devblog/twitter-api-java-tutorial/|a quick tutorial]] (148 followers)
 +    * [[http://www.winterwell.com/software/jtwitter.php|WinterWell, another twitter library for java]] (10 watchers in [[http://www.github.com]])
 +
 +===== Oauth libraries in java =====
 +
 +[[https://github.com/fernandezpablo85/scribe-java|Scribe (178 people watching in github)]]
 +
 +I've tried the example of the Twitter library for this library and it doesn't work, so I've decided to abandon this library.
 +
 +[[http://docs.spring.io/spring-security/oauth/|OAuth for spring security (138 people watching in github)]]
 +
 +[[http://code.google.com/p/oauth-signpost/|Singpost (starred by 403 users, no activity since feb 2012)]]
 +
 +[[https://code.google.com/p/oauth/|Official OAuth library, 31 commiters, starred by 1074 users, may languages supported]]
 +
 +An example to see it working: 
 +
 +[[http://oauthexample.appspot.com/Welcome]]
 +
 +Other libraries and links: 
 +
 +    * [[http://code.google.com/p/google-oauth-java-client/|Google OAuth Client Library for Java]] e 
 +    * [[http://oauth.net/code/|List of implemmentations from oauth.net]]
 +    * [[http://oauth.googlecode.com/|oauth - google code]] e [[http://www-10.lotus.com/ldd/appdevwiki.nsf/xpDocViewer.xsp?lookupName=IBM+Social+Business+Toolkit+documentation#action=openDocument&res_title=Configuring_the_OAuth_provider_with_the_Java_library_sbt&content=pdcontent|instrucciones sobre como instalar este repositorio de codigo]]
 +    * [[https://developer.mastercard.com/portal/display/api/Java+OAuth+Sample+Code|Java OAuth Sample Code (mastercard)]]
 +    * [[https://publisherwiki.atlassian.net/wiki/display/dev/OAuth+1.0+Sample+Java+Client|OAuth 1.0 Sample Java Client]]
 +    * [[http://developer.linkedin.com/thread/1745|How To: LinkedIn OAuth with Java ]]
 +
 +
 +===== 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://blog.varonis.com/introduction-to-oauth/|Introduction to OAuth in plain english]]
 +
 +If you are like me, probably OAuth is a technology that doesn't seem clear to you. I encourage you to navigate and read about this topic. Moreover, this is the base of many "Sign in with Twitter", "Sign in with facebook" and the like. 
 +
 +
 +
 +
 +===== Facebook =====
 +
 +http://restfb.com/
 +
 +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.