<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Nite Viva Developer&#039;s Blog</title>
	<atom:link href="http://blog.niteviva.com/feed" rel="self" type="application/rss+xml" />
	<link>http://blog.niteviva.com</link>
	<description>Documenting the development of NiteViva</description>
	<lastBuildDate>Tue, 22 Jun 2010 12:53:03 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.6</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Facebook Pages the Java way</title>
		<link>http://blog.niteviva.com/development/facebook-pages-the-java-way</link>
		<comments>http://blog.niteviva.com/development/facebook-pages-the-java-way#comments</comments>
		<pubDate>Tue, 22 Jun 2010 09:15:41 +0000</pubDate>
		<dc:creator>chico</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[facebook]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[tech]]></category>

		<guid isPermaLink="false">http://blog.niteviva.com/?p=172</guid>
		<description><![CDATA[If you&#8217;re ready to jump on the social bandwagon, you might consider creating a Facebook Page to extend your social reach. Creating a Facebook Page couldn&#8217;t be easier, but posting up content can be a drag.. so why not automate it?
The content on our Facebook Page &#8211; http://facebook.com/giglondon &#8211; is fully automated, from creating daily [...]]]></description>
			<content:encoded><![CDATA[<p>If you&#8217;re ready to jump on the social bandwagon, you might consider creating a Facebook Page to extend your social reach. Creating a Facebook Page couldn&#8217;t be easier, but posting up content can be a drag.. so why not automate it?</p>
<p>The content on our Facebook Page &#8211; <a href="http://facebook.com/giglondon" target="_blank">http://facebook.com/giglondon</a> &#8211; is fully automated, from creating daily events to posting updates of the best gigs each month. The first obstacle that we face in connecting with Facebook is that we need an API Key/Secret and a Session Key.<span id="more-172"></span></p>
<h3>Facebook API Key/Secret and Session Key</h3>
<ul>
<li>For the API Key and Secret, go to <a href="http://www.facebook.com/developers" target="_blank">http://www.facebook.com/developers</a> and click on the &#8216;Set Up New Application&#8217; button, which gives you a unique API Key and Secret for your application.
</li>
<li>To get a Session Key, do the following:</li>
<ol>
<li>Copy &amp; paste the following URL into a browser, remembering to replace <b>&lt;API Key&gt;</b> with your unique API Key:
<div style="word-wrap: break-word; padding:5px;">http://www.facebook.com/login.php?api_key=<b>&lt;API&nbsp;Key&gt;</b>&amp;connect_display=popup&amp;v=1.0<wbr>&amp;next=http://www.facebook.com/connect/login_success.html&amp;cancel_url=http://www.facebook.com/connect/login_failure.html&amp;fbconnect=true&amp;return_session=true&amp;session_key_only=true&amp;req_perms=create_event,publish_stream,offline_access</div>
<li>Login with the Facebook account that is an Admin user of your Facebook Page (<b>important!</b>).</li>
<li>Click on &#8216;Allow&#8217; until you get to the Success page, whereby the redirect URL will be something like:
<div style="word-wrap: break-word; padding:5px;">http://www.facebook.com/connect/login_success.html?session={&#8221;session_key&#8221;:<b>&lt;Session&nbsp;Key&gt;</b>,&#8221;uid&#8221;:<b>&lt;User&nbsp;Id&gt;</b>,&#8221;expires&#8221;:0,&#8221;secret&#8221;:&lt;Session&nbsp;Secret&gt;,&#8221;sig&#8221;:&lt;Signature&gt;}</div>
</li>
<li>
Copy the <b>&lt;Session Key&gt;</b> and <b>&lt;User Id&gt;</b> values from that URL and keep them safe.
</li>
</ol>
</li>
</ul>
<p>If you have any difficulty with what&#8217;s been outlined above, I encourage you to look at <a href="http://blog.theunical.com/facebook-integration/facebook-java-api-example-to-publish-on-wall/" target="_blank">this great blog</a>, which will take you step by step through how to generate the Facebook API Key/Secret and Session Key.</p>
<h3>Facebook Java API</h3>
<p>The <a href="http://code.google.com/p/facebook-java-api" target="_blank">Facebook Java API</a> is a Facebook client that can be used to push content over to a Facebook Page. </p>
<p>The easiest option is to include the client library as a dependency in your Maven pom.xml file. If Maven isn&#8217;t your preferred option, download the library from <a href="http://code.google.com/p/facebook-java-api/downloads/list" target="_blank">here</a>.</p>
<pre>&lt;dependency&gt;
  &lt;groupId&gt;com.google.code.facebookapi&lt;/groupId&gt;
  &lt;artifactId&gt;facebook-java-api&lt;/artifactId&gt;
  &lt;version&gt;3.0.2&lt;/version&gt;
&lt;/dependency&gt;</pre>
<h3>Posting Your First Facebook Page Update</h3>
<pre name="code" class="java">
...
import com.google.code.facebookapi.*;
...
  // Replace the values with your unique API Key/Secret and Session Key!
  public final static String FACEBOOK_API_KEY = "API KEY";
  public final static String FACEBOOK_API_SECRET = "API SECRET";
  public final static String SESSION_KEY = "SESSION KEY";

  // Replace the User Id with the Admin User Id of the Facebook Page
  public final static String USER_ID = "USER ID";

  // Replace the Facebook Page Id - if you don't know your Facebook Page Id this link
  // will tell you how to find it: http://support.wibiya.com/entries/187061-how-to-find-your-facebook-fan-page-id
  public final static String FACEBOOK_PAGE_ID = "FACEBOOK PAGE ID";

  public void myFirstPost() throws Exception {
    // First we create the client with the API Key/Secret and Session Key
    FacebookJsonRestClient client = new FacebookJsonRestClient(FACEBOOK_API_KEY, FACEBOOK_API_SECRET, SESSION_KEY);

    // Image attachment to make our first post more eye catching (note: you can add as many images as you like)
    Attachment attachment = new Attachment();
    // The first URL is the image URL, the second is the URL that the user is taken to when they click the image
    attachment.addMedia(
      new AttachmentMediaImage(
        "http://blog.niteviva.com/wp-content/uploads/2010/06/cool.jpg",
        "http://blog.niteviva.com/wp-content/uploads/2010/06/cool.jpg"));

    // Post your first post!
    client.stream_publish(
      "Snoopy is too cool for school",
      attachment, null, new Long(FACEBOOK_PAGE_ID), new Long(USER_ID));
  }
</pre>
<p>If all goes well then you will see the post on the wall of your Facebook Page .. sweet!</p>
<p><img border="1" src="http://blog.niteviva.com/wp-content/uploads/2010/06/facebookpost.jpg" alt="facebook post" width="378" height="136" class="alignnone size-full wp-image-233" /></p>
<h3>Facebook Page Events</h3>
<p>We can do so much more with the <a href="http://developers.facebook.com/docs" target="_blank">Facebook API</a> .. here&#8217;s a code snippet on creating an event:</p>
<pre name="code" class="java">
  public void newEvent() throws Exception {
    FacebookJsonRestClient client = new FacebookJsonRestClient(FACEBOOK_API_KEY, FACEBOOK_API_SECRET, SESSION_KEY);

    // Convert the event date/time to seconds
    Date eventDateTime = new SimpleDateFormat("yyyy-MM-dd HH:mm").parse("2010-12-25 21:00");
    String eventTimeInSeconds = new Long(eventDateTime.getTime() / 1000).toString();

    // Create event info map
    Map&lt;String, String&gt; event = new HashMap&lt;String, String&gt;();
    event.put("start_time", eventTimeInSeconds);
    event.put("name", "Snoopy &amp; Friends Xmas Party");
    event.put("location", "Charlie Brown's Crib");
    event.put("page_id", FACEBOOK_PAGE_ID);
    event.put("privacy_type", "OPEN");
    event.put("description", "FYI Snoopy loves root beer and pizza!");

    // Post new event
    client.events_create(event);
  }
</pre>
<p><img border="1" src="http://blog.niteviva.com/wp-content/uploads/2010/06/snoopy-xmasparty.jpg" alt="snoopy-xmasparty" width="549" height="187" class="alignnone size-full wp-image-237" /></p>
<p>Sadly the Facebook Java API client library doesn&#8217;t (at the time of writing) support adding images to events out of the box. The only option is to extend the client library code, which we&#8217;ve managed to do successfully. Please leave a comment below if you want more information on that specific issue.</p>
<p>That&#8217;s all folks .. and whatever you do, don&#8217;t forget to like our Facebook Page &#8211; <a href="http://facebook.com/giglondon" target="_blank">http://facebook.com/giglondon</a> <img src='http://blog.niteviva.com/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://blog.niteviva.com/development/facebook-pages-the-java-way/feed</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>Realtime geolocation check-in feeds using Foursquare&#8217;s API</title>
		<link>http://blog.niteviva.com/development/realtime-geolocation-check-in-feeds-using-foursquares-api</link>
		<comments>http://blog.niteviva.com/development/realtime-geolocation-check-in-feeds-using-foursquares-api#comments</comments>
		<pubDate>Thu, 22 Apr 2010 12:07:18 +0000</pubDate>
		<dc:creator>chico</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[foursquare]]></category>
		<category><![CDATA[NiteViva]]></category>
		<category><![CDATA[tech]]></category>

		<guid isPermaLink="false">http://blog.niteviva.com/?p=83</guid>
		<description><![CDATA[In this post we&#8217;re going to be leveraging Foursquare&#8217;s API to get venues near a given geo location and to connect to a user&#8217;s Foursquare account, so that we can pull in their realtime check-in feed.
This has been implemented on our live environment, so for a real live demo go to http://niteviva.com and sign in [...]]]></description>
			<content:encoded><![CDATA[<p>In this post we&#8217;re going to be leveraging <a target="_blank" href="http://groups.google.com/group/foursquare-api/web/api-documentation">Foursquare&#8217;s API</a> to get venues near a given geo location and to connect to a user&#8217;s Foursquare account, so that we can pull in their realtime check-in feed.</p>
<p>This has been implemented on our live environment, so for a real <b>live demo</b> go to <a target="_blank" href="http://niteviva.com">http://niteviva.com</a> and <b>sign in using your Foursquare account</b>. Note that, for account verification and security reasons, you will be asked for your email address when you sign up. You will then be taken to the home page where your Foursquare check-in feed will be displayed on the top right-hand corner.</p>
<p><a target="_blank" href="http://groups.google.com/group/foursquare-api/web/api-documentation">Foursquare&#8217;s API</a> has various <a target="_blank" href="http://groups.google.com/group/foursquare-api/web/libraries">client libraries</a> that we can use to start developing with the API. Here, <a target="_blank" href="http://code.google.com/p/foursquared/">foursquared</a> has been chosen because Java is what we find easy to work with when using third-party APIs. You will need to be comfortable working with Java and Maven to complete the following steps, but even if Java isn&#8217;t your cup of tea, this post is still useful to those of you who are generally interested in getting started with <a target="_blank" href="http://groups.google.com/group/foursquare-api/web/api-documentation">Foursquare&#8217;s API</a>. Case in point, some of what&#8217;s said in this post is based on a <a target="_blank" href="http://www.joesiewert.com/2010/04/how-to-use-the-foursquare-api-with-oauth-and-php/">great blog post</a> by Joe Siewert, which shows how to get started with Foursquare and PHP.<span id="more-83"></span></p>
<h3>Step 1. Download and install the Foursquare client library</h3>
<ol>
<li>Download it <a href="http://foursquared.googlecode.com/files/foursquarelib_2009111500.jar">here</a> or from <a target="_blank" href="http://code.google.com/p/foursquared/">foursquared</a></li>
<li>Install the jar in your local Maven repository, e.g.:</li>
<pre>mvn install:install-file -Dfile=~/Downloads/foursquarelib_2009111500.jar -DgeneratePom=true
-DgroupId=com.joelapenna.foursquare -DartifactId=foursquare -Dversion=2009111500 -Dpackaging=jar</pre>
<li>Include the following dependencies in your pom.xml:
<pre>&lt;dependency&gt;
  &lt;groupId&gt;com.joelapenna.foursquare&lt;/groupId&gt;
  &lt;artifactId&gt;foursquare&lt;/artifactId&gt;
  &lt;version&gt;2009111500&lt;/version&gt;
&lt;/dependency&gt;
&lt;dependency&gt;
  &lt;groupId&gt;xpp3&lt;/groupId&gt;
  &lt;artifactId&gt;xpp3&lt;/artifactId&gt;
  &lt;version&gt;1.1.4c&lt;/version&gt;
&lt;/dependency&gt;
&lt;dependency&gt;
  &lt;groupId&gt;oauth.signpost&lt;/groupId&gt;
  &lt;artifactId&gt;signpost-core&lt;/artifactId&gt;
  &lt;version&gt;1.1&lt;/version&gt;
&lt;/dependency&gt;
&lt;dependency&gt;
  &lt;groupId&gt;oauth.signpost&lt;/groupId&gt;
  &lt;artifactId&gt;signpost-commonshttp4&lt;/artifactId&gt;
  &lt;version&gt;1.1&lt;/version&gt;
&lt;/dependency&gt;</pre>
</li>
</ol>
<h3>Step 2. Code!</h3>
<p>Now you&#8217;re ready to start using the Foursquare API .. well, almost! First you need to write some code.</p>
<pre name="code" class="java">package myapp;

import java.util.ArrayList;
import java.util.List;

import com.joelapenna.foursquare.Foursquare;
import com.joelapenna.foursquare.FoursquareHttpApiV1;
import com.joelapenna.foursquare.Foursquare.Location;
import com.joelapenna.foursquare.types.Group;
import com.joelapenna.foursquare.types.Venue;

/**
 * NoAuthFoursquareService uses Foursquare client to make non authenticated Foursquare calls.
 */
public class NoAuthFoursquareService {

	/** The no auth foursquare. */
	protected final Foursquare noAuthFoursquare;

	/**
	 * Instantiates a new non authenticated foursquare service.
	 */
	public NoAuthFoursquareService() {
	  this.noAuthFoursquare = new Foursquare(new FoursquareHttpApiV1("api.foursquare.com", null, false));
	  noAuthFoursquare.setCredentials("", "");
	}

  	/**
	 * Venues.
	 *
	 * @param latitude the latitude
	 * @param longitude the longitude
	 * @return the group
	 */
	public List&lt;Venue&gt; venues(String latitude, String longitude) throws Exception {

	    // Make Foursquare venues API call
	    Group&lt;Group&lt;Venue&gt;&gt; venues =
	      this.noAuthFoursquare.venues(new Location(latitude, longitude), "", 1, 10);

	    // Convert venues into list
	    List&lt;Venue&gt; venueList = new ArrayList&lt;Venue&gt;();
	    for(Group&lt;Venue&gt; venueGroup: venues) {
	      for(Venue venue: venueGroup) {
	        venueList.add(venue);
	      }
	    }

	    return venueList;
	}
}</pre>
<h3>Step 3. Take it for a test spin</h3>
<pre name="code" class="java">package myapp;

import static org.junit.Assert.assertEquals;
import java.util.List;
import org.junit.Test;

import com.joelapenna.foursquare.types.Venue;

/**
 * Testing non authenticated Foursquare API calls
 */
public class NoAuthFoursquareTest {

  /** The non authenticated foursquare service that's going to be tested. */
  NoAuthFoursquareService noAuthFoursquareService = new NoAuthFoursquareService();

  /**
   * Test call to Foursquare venues API
   *
   * @throws Exception the exception
   */
  @Test
  public void venues() throws Exception {
    List&lt;Venue&gt; venues = noAuthFoursquareService.venues("51.5517", "-0.158826");

    assertEquals(10, venues.size());
    for (Venue venue: venues) {
      System.out.println(
          venue.getName() + ", " + venue.getAddress() + ", " + venue.getCity()
          + " [lat:" + venue.getGeolat() + ", long:" + venue.getGeolong() + "]");
    }
  }
}</pre>
<p>If all goes well, you should see some test output:<br />
<code><br />
1st floor chocolate machine, Mediacom, Camden [lat:51.5517059, long:-0.1588255]<br />
Camden rock, Camden, London [lat:51.5517059, long:-0.1588255]<br />
Centro Cafe, Camden, London [lat:51.5517059, long:-0.1588255]<br />
Muang thai, Camden, London [lat:51.5517059, long:-0.1588255]<br />
Somerfield, Camden, London [lat:51.5517059, long:-0.1588255]<br />
the ice wharf, Camden, London [lat:51.5517059, long:-0.1588255]<br />
Palushi's barber, Southampton Road, Camden Town [lat:51.55153896107019, long:-0.15754222869873047]<br />
Lord Weetch's Manor, 9a Parkhill Rd, Camden Town [lat:51.550125, long:-0.1585858]<br />
The IDM, 1 Park Road, London [lat:51.5504938, long:-0.1601123]<br />
The Lord Stanley, 51 camden park road, London [lat:51.5516975, long:-0.1605962]<br />
</code></p>
<h3>Step 4. Realtime Geolocation Check-in Feeds</h3>
<p>Here it get&#8217;s that little bit more tricky. We need the user to authorize our application so we can get access to their realtime check-ins. From now onwards, it helps to understand how <a target="_blank" href="http://en.wikipedia.org/wiki/OAuth">OAuth</a> works.</p>
<p>First, you need an application key and secret from Foursquare. Create a Foursquare test account and go to <a target="_blank" href="http://foursquare.com/oauth">http://foursquare.com/oauth</a>. Register a new consumer with the callback URL &#8216;http://localhost:8080/foursquare/oauth&#8217;, and then Foursquare will give you a unique consumer key and secret.</p>
<p>Now, some more code <img src='http://blog.niteviva.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<pre name="code" class="java">package myapp;

import oauth.signpost.OAuthProvider;
import oauth.signpost.basic.DefaultOAuthProvider;
import oauth.signpost.commonshttp.CommonsHttpOAuthConsumer;
import oauth.signpost.signature.SignatureMethod;

import java.util.List;

import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.DefaultHttpClient;

import com.joelapenna.foursquare.Foursquare;
import com.joelapenna.foursquare.FoursquareHttpApiV1;
import com.joelapenna.foursquare.http.AbstractHttpApi;
import com.joelapenna.foursquare.http.HttpApiWithOAuth;
import com.joelapenna.foursquare.parsers.CheckinParser;
import com.joelapenna.foursquare.parsers.GroupParser;
import com.joelapenna.foursquare.parsers.UserParser;
import com.joelapenna.foursquare.types.Checkin;
import com.joelapenna.foursquare.types.Group;
import com.joelapenna.foursquare.types.User;

/**
 * FoursquareService uses Foursquare client to make authenticated Foursquare API calls.
 */
public class OAuthFoursquareService {

	/** The Constant URL_API. */
	private static final String URL_API = "http://api.foursquare.com/v1";

	/** The Constant URL_API_USER. */
	private static final String URL_API_USER = URL_API + "/user";

	/** The Constant URL_API_HISTORY. */
	private static final String URL_API_HISTORY = URL_API + "/history";

	/** The http client. */
	protected final DefaultHttpClient mHttpClient = AbstractHttpApi.createHttpClient();

	/** The consumer key. */
	protected final String consumerKey;

	/** The consumer secret. */
	protected final String consumerSecret;

	/**
	 * Instantiates a new OAuth foursquare service.
	 */
	public OAuthFoursquareService(String consumerKey, String consumerSecret) {
	  this.consumerKey = consumerKey;
	  this.consumerSecret = consumerSecret;
	}

	/**
	 * New foursquare OAuth provider.
	 *
	 * @return the OAuth provider
	 */
	public OAuthProvider newOAuthProvider() {
	  OAuthProvider provider = new DefaultOAuthProvider(
	      new CommonsHttpOAuthConsumer(consumerKey, consumerSecret, SignatureMethod.HMAC_SHA1),
        "http://foursquare.com/oauth/request_token",
        "http://foursquare.com/oauth/access_token",
        "http://foursquare.com/oauth/authorize");
	  return provider;
	}

	/**
	 * Gets the user.
	 *
	 * @param token the token
	 * @param secret the secret
	 * @return the user
	 */
	public User getUser(String token, String secret) throws Exception {
	  HttpApiWithOAuth mHttpApi = new HttpApiWithOAuth(mHttpClient, null);
	  mHttpApi.setOAuthConsumerCredentials(consumerKey, consumerSecret);
	  mHttpApi.setOAuthTokenWithSecret(token, secret);
	  HttpGet httpGet = mHttpApi.createHttpGet(URL_API_USER);
	  return (User) mHttpApi.doHttpRequest(httpGet, new UserParser());
	}

	/**
	 * Checkin History.
	 *
	 * @param token the token
	 * @param secret the secret
	 * @return the group
	 */
	@SuppressWarnings("unchecked")
  	public List&lt;Checkin&gt; history(String token, String secret) throws Exception {
  	  HttpApiWithOAuth mHttpApi = new HttpApiWithOAuth(mHttpClient, null);
      mHttpApi.setOAuthConsumerCredentials(consumerKey, consumerSecret);
      mHttpApi.setOAuthTokenWithSecret(token, secret);
      HttpGet httpGet = mHttpApi.createHttpGet(URL_API_HISTORY);
      Group&lt;Checkin&gt; checkinGroup = (Group&lt;Checkin&gt;) mHttpApi.doHttpRequest(httpGet, new GroupParser(new CheckinParser()));
      return checkinGroup.subList(0, checkinGroup.size());
	}

	/**
	 * New OAuth client.
	 *
	 * @param token the token
	 * @param secret the secret
	 * @return the foursquare
	 */
	protected Foursquare newOAuthClient(String token, String secret) {
	  Foursquare foursquareOAuthClient =
	    new Foursquare(new FoursquareHttpApiV1("api.foursquare.com", null, true));
	  foursquareOAuthClient.setOAuthConsumerCredentials(consumerKey, consumerSecret);
	  foursquareOAuthClient.setOAuthToken(token, secret);
	  return foursquareOAuthClient;
	}

}</pre>
<p>To start using the OAuthFoursquareService, you have to hook it up into the web layer. I&#8217;m not going to go in depth at this stage, but here&#8217;s a code example of how it can be done using a Spring MVC controller:</p>
<pre name="code" class="java">package myapp;

import oauth.signpost.OAuthProvider;
import com.joelapenna.foursquare.types.Checkin;
import com.joelapenna.foursquare.types.User;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.View;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.view.RedirectView;

/**
 * FoursquareController handles oauth requests (authorize and oauth callback)
 */
@Controller
@RequestMapping("/foursquare")
public class FoursquareController {

	/** The foursquare service. */
	@Autowired
	public OAuthFoursquareService foursquareService;

	/** The Constant accessTokens that stores OAuth access tokens */
	public static final Map&lt;String, String[]&gt; accessTokens = new ConcurrentHashMap&lt;String, String[]&gt;();

	/**
	 * Authorize - redirects user to a foursquare authorization url
	 *
	 * @param returnUrl the return url
	 * @throws Exception the exception
	 */
	@RequestMapping(value = "/authorize", method = RequestMethod.GET)
	public View authorize(HttpSession session) throws Exception {

	  // Get authorize url, save OAuthProvider into HTTP session (retrieved in oauth callback method)
	  OAuthProvider provider = foursquareService.newOAuthProvider();
	  String authorizeUrl = provider.retrieveRequestToken("http://localhost:8080/foursquare/oauth");
	  session.setAttribute("foursquare", provider);

	  return new RedirectView(authorizeUrl);
	}

	/**
	 * OAuth Callback.
	 *
	 * @param oauthToken the oauth token
	 * @throws Exception the exception
	 */
	@RequestMapping(value = "/oauth", method = RequestMethod.GET)
  	public View oauth(
  		HttpSession session, @RequestParam("oauth_token") String oauthToken) throws Exception {

	  // Get OAuthProvider from HTTP session (set in authorize method), and get access token and secret
	  OAuthProvider provider = (OAuthProvider) session.getAttribute("foursquare");
	  provider.retrieveAccessToken("http://localhost:8080/foursquare/oauth");
	  String token = provider.getConsumer().getToken();
	  String tokenSecret = provider.getConsumer().getTokenSecret();	  

	  // Get user info from foursquare API
	  User user = foursquareService.getUser(token, tokenSecret);

	  // NOTE: Put access token and secret in accessToken map, which is fine for this example but
	  // normally the access token and secret would be stored in a database!
	  accessTokens.put(user.getId(), new String[]{token, tokenSecret});	  

	  return RedirectView("http://localhost:8080/foursquare/checkins/" + user.getId());
	}

	/**
	 * Checkins.
	 *
	 * @param userId the user id
	 * @return the model and view
	 * @throws Exception the exception
	 */
	@RequestMapping(value = "/checkins/{id}", method = RequestMethod.GET)
  	public ModelAndView checkins(@PathVariable String id) throws Exception {
	  String[] accessToken = accessTokens.get(id);

	  if (null == accessToken)
	    throw new Exception("Foursquare user not yet authenticated [" + id + "]");

	  // Get user check-ins from foursquare API
	  List&lt;Checkin&gt; checkins = foursquareService.history(accessToken[0], accessToken[1]);

	  Map&lt;String, List&lt;Checkin&gt;&gt; model = new HashMap&lt;String, List&lt;Checkin&gt;&gt;();
      model.put("checkins", checkins);
	  return new ModelAndView("checkins", model);
	}

}</pre>
<p>The above web flow works as follows:</p>
<ol>
<li>The user clicks on a HTML link that directs them to http://localhost:8080/foursquare/authorize</li>
<li>The user is redirected to the Foursquare website, which asks the user to authorize our application so we can access their Foursquare realtime check-in feed</li>
<li>The user is taken back to http://localhost:8080/foursquare/oauth, which accepts and stores the new access token for that user</li>
<li>The user is finally redirected to http://localhost:8080/foursquare/checkins/{id}, which calls the Foursquare API to get the user&#8217;s realtime check-in feed</li>
</ol>
<p>Hope this post has been useful in explaining how you can get started with <a target="_blank" href="http://groups.google.com/group/foursquare-api/web/api-documentation">Foursquare&#8217;s API</a>.<br />
If you have any questions or feedback, please leave a comment.</p>
<p>Don&#8217;t forget you can try out a real <b>live demo</b> at <a target="_blank" href="http://niteviva.com">http://niteviva.com</a> .. enjoy <img src='http://blog.niteviva.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://blog.niteviva.com/development/realtime-geolocation-check-in-feeds-using-foursquares-api/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Quick Freemarker tip</title>
		<link>http://blog.niteviva.com/development/quick-freemarker-tip</link>
		<comments>http://blog.niteviva.com/development/quick-freemarker-tip#comments</comments>
		<pubDate>Wed, 13 Jan 2010 11:56:39 +0000</pubDate>
		<dc:creator>Graham</dc:creator>
				<category><![CDATA[Development]]></category>

		<guid isPermaLink="false">http://blog.niteviva.com/?p=65</guid>
		<description><![CDATA[We&#8217;ve started using Freemarker for our web and email templates, but one problem we had is with syntax highlighting in Eclipse, it just showed them as one black and white mass of code.
One quick solution was to open *.ftl with the WTP HTML editor, to do that right click on an ftl file and select [...]]]></description>
			<content:encoded><![CDATA[<p>We&#8217;ve started using <a href="http://freemarker.org/">Freemarker</a> for our web and email templates, but one problem we had is with syntax highlighting in Eclipse, it just showed them as one black and white mass of code.</p>
<p>One quick solution was to open *.ftl with the WTP HTML editor, to do that right click on an ftl file and select &#8216;open with&#8230;&#8217; and follow the prompts. The only problem is that Eclipse then started showing errors on a lot of the templates so we had to disable validation . To do the same, open Eclipse preferences and find the Web/Html file/validation page screen and set all of the values set to  &#8217;Error&#8217; to &#8216;Warning&#8217; or &#8216;Ignore&#8217;.</p>
<p>A quick refresh and rebuild removes all of those pesky build error markers <img src='http://blog.niteviva.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://blog.niteviva.com/development/quick-freemarker-tip/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Shiny new build system</title>
		<link>http://blog.niteviva.com/development/or-shiny-new-build-system</link>
		<comments>http://blog.niteviva.com/development/or-shiny-new-build-system#comments</comments>
		<pubDate>Wed, 13 Jan 2010 09:44:19 +0000</pubDate>
		<dc:creator>Graham</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[CI]]></category>
		<category><![CDATA[continuous integration]]></category>
		<category><![CDATA[Maven]]></category>

		<guid isPermaLink="false">http://blog.niteviva.com/?p=59</guid>
		<description><![CDATA[Up until now we&#8217;ve been happy enough to manage the build process manually from Github, but after a large rewrite of some sections (more to follow on that in another post) we&#8217;ve reached a point where we needed to put something more maintainable in place. Seeing as I&#8217;ve been through this a few times before [...]]]></description>
			<content:encoded><![CDATA[<p>Up until now we&#8217;ve been happy enough to manage the build process manually from Github, but after a large rewrite of some sections (more to follow on that in another post) we&#8217;ve reached a point where we needed to put something more maintainable in place. Seeing as I&#8217;ve been through this a few times before at companies like Channel4, Disney and most recently at the BBC, I decided to stick to a set up that I know works well really for Java development.<span id="more-59"></span></p>
<p>First of all I started moving the sub-projects over to Maven, it may not be the most popular build system right now, but nothing comes close to Maven for Java development right now. Once the project hierarchies were in place I had to put a private repository in place so we could share libraries and plugins. I spent a few hours looking at repository managers at this point, but we&#8217;ve decided to go without one for now. I know from experience that this will become an issue later when we want to install additional libraries that don&#8217;t exist in public repositories, think javax-*, but with a small team of developers we can afford to skip it for now.</p>
<p>I thought about setting up the deployments to use Webdav, I&#8217;d used that at one of my old client&#8217;s sites and it worked pretty well, but seeing as we already have an SSH key setup in place, including extensive use of ~/.ssh/config files, using SSH &amp; SCP was quicker and easier. One little trick I picked up this time around was to change the addresses for deployments from scp://&#8230; to scpexe:// so the system scp application is used rather than the Maven wagon so our URLs can use our SSH aliases.</p>
<p>Next up, we needed a CI server so don&#8217;t have to run the live builds from our laptops anymore! I&#8217;ve tried quite a few CI servers over the years, but I think Hudson has stabilised a lot over the last couple of years so I&#8217;ve decided to drop it in here too. I have a few issues with Hudson&#8217;s UI, I&#8217;ve seen installations with 300+ jobs and it becomes difficult to find anything without a grouping scheme (I don&#8217;t think views cut it), and it takes too long to navigate to some features, but on the whole it is a great little tool.</p>
<p>The two main differences between the build system we have now and the ones I&#8217;ve used before are;</p>
<ol>
<li>Authentication, some have used VPN and left the services open internally whilst others have made extensive use of x509 certificates, here I&#8217;ve set up SSH keys to authenticate developers.</li>
<li>We&#8217;re using Git for SCM so you need to figure out your repository layout up-front. I&#8217;ll probably write another post about our choice of Git over the incumbent open source SCM, but the combination of Git and Github has worked really well for us and fits into our SSH key setup nicely.</li>
</ol>
<p>All in, it only took a few hours to get everything up and running. I wasted part of that looking at repository managers before realising that we just don&#8217;t need one yet. The rest is all standard issue, but it does impress me how Maven and Hudson have grown up since I used them first, Maven especially, it was a terrible toddler but it has really grown up over the last year.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.niteviva.com/development/or-shiny-new-build-system/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Realtime Twitter Reactions using JQuery</title>
		<link>http://blog.niteviva.com/development/realtime-twitter-reactions-using-jquery</link>
		<comments>http://blog.niteviva.com/development/realtime-twitter-reactions-using-jquery#comments</comments>
		<pubDate>Fri, 27 Nov 2009 14:34:19 +0000</pubDate>
		<dc:creator>chico</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[jquery]]></category>
		<category><![CDATA[twitter]]></category>

		<guid isPermaLink="false">http://blog.niteviva.com/?p=10</guid>
		<description><![CDATA[
$(document).ready(function() {
	$("#demo-realtime-reactions").getPageRealtimeReactions({
		query: "niteviva OR Realtime Twitter Reactions using JQuery OR http://blog.niteviva.com/development/realtime-twitter-reactions-using-jquery OR http://tinyurl.com/yfahkgd OR http://bit.ly/4HUbdf  OR http://bit.ly/7QB1PQ",
		numTweets: 5,
		loaderText: "Loading ...",
		slideIn: true,
		showHeading: false
	});
});


I&#8217;ve taken inspiration from an awesome jquery plugin from coda and developed some jquery code that goes and fetches realtime twitter reactions.
To begin, download the source and include the following scripts in your [...]]]></description>
			<content:encoded><![CDATA[<p><script type="text/javascript">
$(document).ready(function() {
	$("#demo-realtime-reactions").getPageRealtimeReactions({
		query: "niteviva OR Realtime Twitter Reactions using JQuery OR http://blog.niteviva.com/development/realtime-twitter-reactions-using-jquery OR http://tinyurl.com/yfahkgd OR http://bit.ly/4HUbdf  OR http://bit.ly/7QB1PQ",
		numTweets: 5,
		loaderText: "Loading ...",
		slideIn: true,
		showHeading: false
	});
});
</script></p>
<div id="demo-realtime-reactions" style="width:95%;"></div>
<p>I&#8217;ve taken inspiration from <a href="http://coda.co.za/blog/2008/10/26/jquery-plugin-for-twitter" target="_blank">an awesome jquery plugin from coda</a> and developed some jquery code that goes and fetches realtime twitter reactions.<span id="more-10"></span></p>
<p>To begin, download the <a href="http://blog.niteviva.com/wp-content/themes/niteviva/source/jquery-realtime-twitter-reactions-source.zip">source</a> and include the following scripts in your page:</p>
<pre name="code" class="html:nogutter">
&lt;script type="text/javascript" src="js/jquery-1.3.2.js"&gt;&lt;/script&gt;
&lt;script type="text/javascript" src="js/jquery.page-realtime-twitter-reactions.js"&gt;&lt;/script&gt;
</pre>
<p>Next, add a &#8220;page-realtime-reactions&#8221; div element to your page, wherever you want the realtime reactions to appear:</p>
<pre name="code" class="html:nogutter">&lt;div id="page-realtime-reactions"&gt;&lt;/div&gt;</pre>
<p>Finally, add the following jquery code, changing the query parameter to suit your needs:</p>
<pre name="code" class="html:nogutter">
&lt;script type="text/javascript"&gt;
&nbsp;&nbsp;$(document).ready(function() {
&nbsp;&nbsp;&nbsp;&nbsp;$("#page-realtime-reactions").getPageRealtimeReactions({
&nbsp;&nbsp;&nbsp;&nbsp;query: "Realtime Twitter Reactions using JQuery OR http://blog.niteviva.com/development/realtime-twitter-reactions-using-jquery OR http://tinyurl.com/yfahkgd",
&nbsp;&nbsp;&nbsp;&nbsp;numTweets: 5,
&nbsp;&nbsp;&nbsp;&nbsp;loaderText: "Loading ...",
&nbsp;&nbsp;&nbsp;&nbsp;slideIn: true,
&nbsp;&nbsp;&nbsp;&nbsp;showHeading: false
&nbsp;&nbsp;&nbsp;&nbsp;});
&nbsp;&nbsp;});
&lt;/script&gt;
</pre>
<p>Hope you enjoy playing with this neat little plugin, and why not <a href="http://twitter.com/home?status=realtime twitter reactions using jquery http://tinyurl.com/yfahkgd" target="_blank">tweet about it</a> (comments are so 1990!), and be amazed when you see your tweet appear above <img src='http://blog.niteviva.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://blog.niteviva.com/development/realtime-twitter-reactions-using-jquery/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>First post!</title>
		<link>http://blog.niteviva.com/development/first-post</link>
		<comments>http://blog.niteviva.com/development/first-post#comments</comments>
		<pubDate>Sun, 08 Nov 2009 21:03:25 +0000</pubDate>
		<dc:creator>Graham</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[NiteViva]]></category>

		<guid isPermaLink="false">http://blog.niteviva.com/?p=3</guid>
		<description><![CDATA[Finally got WP running with Nginx and FCGI on our Ubuntu server. We&#8217;ve got loads of posts planned so why not add our feed to your reader to keep up to date with the goings on at Nite Viva?
]]></description>
			<content:encoded><![CDATA[<p>Finally got WP running with Nginx and FCGI on our Ubuntu server. We&#8217;ve got loads of posts planned so why not add our feed to your reader to keep up to date with the goings on at Nite Viva?</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.niteviva.com/development/first-post/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

