Facebook's Places
With Facebook's introduction of Places, they have given those of us on the interwebs another way digitally to check-in to our favorite venues in the physical world, similar to the likes of Gowalla and Foursquare. Places allows you to let your friends know where you are, as well as check in any friends that may be there with you. There is a bit more to it than that, so if you want some more information on what places is and how it works, you can visit the Facebook Places page.
So why is this relevant? Well to go along with the Places, Facebook has updated their Graph API to allow access to this new feature. For now us basic developers are only able to get information on the checkins, but we should be able to actually perform the checkins and insert data in the near future. A live demo of the application can be found here. So let's get started...
Most of my previous examples have been using the very hand .Net Facebook SDK, but this time around I decided to go with the Facebook Javascript SDK. Since the SDK is pretty simple to get started with, I'll assume you already know where to start and jump right into dealing with the new Places feature of the Graph API. One thing to note is that you will need to pass in the user_checkins extended permission to your login call in order to authorize your application to get your check-in data.
Getting your Check-ins
Using the javascript sdk, we will make a call to the FB.api method, formatting our query like "/{user_id}/checkins". This will make the call to the graph api and return us a list of json objects of your recent checkins including the name of the location and the latitude and longitude that we'll be using in this example. The code for this looks a little someting like this:
// get user's recent checkins
FB.api('/' + uid + '/checkins', function (res) {
for (var i = 0; i < res.data.length; i++) {
addMarker(res.data[i].place.location.latitude,
res.data[i].place.location.longitude,
res.data[i].place.name);
}
}
Once the data has been returned from Facebook, we'll loop through the list of places json objects and then call another method we created, addMarker, which will add our places to an instance of google maps. When running the demo, there is a google maps instance that we will be using to plot our check-ins on to give us some visual reference to where we've been. So, to add a marker to our map, we use the following function:
function addMarker(lat, long, title) {
var latlng = new google.maps.LatLng(lat, long);
var marker = new google.maps.Marker({
position: latlng,
map: map,
title: title
});
}
So that's it. With the Graph API and Javascript SDK from Facebook, it's really simple to go out and grab all of your check-ins.
Code
As always, here is a link to download the full source code for this demo. Enjoy!
Facebook_Places.zip (28.16 kb)