How to display your latest foursquare check-in details on your blog

You liked this post, share it !
foursquare-php

Edit (28th August 2011) This post is deprecated as Foursquare now requires Libraries/softs to use the OAuth protocol to authenticate users. The updated version of the code and how to install it explained in this post

One of the coolest feature of Google Lattitude is the widget that you can add to your blog or site to display your current location. Since I am already using Foursquare, I wanted to do the same by displaying my latest check-in. Turnout that foursquare provides an API to retrieve your latest check-in details, but I couldn’t find a code to create a widget from it. To fill this gap I wrote a small PHP class that fetches check-in data from Foursquare and generate a map for it by using Google map API. Using this class you can easily generate a widget that looks like the one below in less that 5 lines of code.

foursquare-php example of use

Since I might not be the only one to find this useful, I made the library available from here. Once you have it downloaded you can create your own widget by adding the following code :


/*
* Foursquare latest check-in widget example.
* Example of a webpage that display a widget that uses the foursquare.php class to
* connect to foursquare and retrive your last check-in details and the coresponding
* google map
* Author: Elie Bursztein (fourlocfetcher@elie.im)
* URL:
* License: GPL
*/

require_once 'foursquare.php'; //loading the class
$fq = new fourSquare("login", "pass"); //fetching the check-in data
?>

Last known location:



venueName?> (venueType?>)



"comment?>"

You should now have a fully functional widget :) Note that the function $fq->getMapUrl() accepts many more arguments that let you customizes even further how the map look like. The full list of arguments is available in the google doc page and in the class directly.

If you think of features that you would like to see added or if you think I should do a WordPress plugin, then let me know. I will see what I can do :)

Elie Bursztein is a researcher at Google where he works on fixing Internet security and privacy problems.
  • http://digitalcortex.net Tom Saunter

    Hi Elie, very pleased to meet you!
    I believe there’d be a real interest in seeing this integrated into a WordPress plugin. There’s a slot ready and waiting for it in my sidebar! Until that time, may I ask what steps we need take to get this to work without a plugin?
    Yours,
    Tom

  • http://www.downer.nl/ Downer

    Cool! Got it working, but a WordPress plugin would be nice ;-)

  • http://digitalcortex.net Tom Saunter

    I’ve actually gone and built this into a WordPress widget. I’m pretty pleased with it. It’ll be available at http://digitalcortex.net as soon as I’ve finished tweaking the code.

    Elie, you are fully credited in the code.

    Many thanks for sharing,
    Tom

  • admin

    @Downer and @tom I was waiting to have a more complete class to do a wordpress pluging but I can certainly make one.

    @Tom if you have any issue with making your wordpress plugin, don’t sweat on it it will be very fast for me to integrate it.

    I should have a new version of the lib by the end of the weekend.

  • http://dannss.com dannss

    Hi, I’ve been looking online and trying to play around with your code but can’t seem to get it to work.

    I have changed the login and password to mine own (keeping the quotes) and also changed the foursquare.php to my hosted php file including the changed username and password what am I doing wrong?

  • http://www.downer.nl/ Anka (Downer)

    Hi Elie, nice work!
    Earlier this week i found Tom’s new widget on the WordPress site, i use that on my blog now.

    Thanks anyway ;-)

  • Elie

    @Dannss do you have at least php 5.2 ? the lib use json_decode which is not available in previous version. I need to update the code to insert a debug message about this.

    @Anka Great ! his plugin is base on my lib :)

  • Naveen

    I have the foursquare integration working based on your code. Thank You. How do you go about retrieving and displaying the current location of the user on a mobile device? Any ideas! If you have done similar work on google latitude or can point to a library that enables google latitude integration on mobile devices including determining current location and check in that will be helpful. – Thanks, Naveen

  • Elie

    Hi Naveen,

    Nope I haven’t looked at Google Lattitude yet but it is certainly a good idea. I have been swamp the last few weeks because of conferences but I will get back to the location library pretty quickly.
    What do you mean by locating a mobile user ? Do you mean from a web site ?

  • mickeyb

    just can’t get this to work. got rid of a t-function error on the description but now getting this

    Last known location:
    ()
    <img src="
    Fatal error: Call to a member function getMapUrl() on a non-object in /home/channon/public_html/4square.php on line 3

    am now giving up

  • Mickeyb

    finally got this to work – and have to say it’s excellent!!! It would be great if it was possible to include an image taken at the checkin, but I’m very happy with it

    • Elie

      @mickeyb I will look into it. It has been a long time without update :) I need to get back at it

      • Andi Saleh

        Great widget, Elie. Thanks. I just found this a couple of weeks ago and integrated it to my blog.

        I just realized this earlier today that it has stopped working, probably because foursquare phased out the old API starting this month. Can you kindly advise how we can switch it with the v2 API and use it as easily as you made it with the old one? Or is there any chance that you could spare some time to update it? We would all definitely appreciate it.

        Thanks again! :)

        • https://elie.im Elie Bursztein

          The new version is close to completion. It will be as easy as the previous one, except the setup phase that requires to get the oauth token. Should be up tomorrow night PST.

        • https://elie.im Elie Bursztein

          You can now download the new version :)

        • Andi Saleh

          That’s great, Elie. Thanks heaps!! :)

          • https://elie.im Elie Bursztein

            Thanks :)

  • http://koked.com/ 8sic sex video tmui

    1YT6A1btELI.. Smashing :)

  • http://jobberies.com Balboa

    great tutorial…

  • Mickey

    stopped working now. could this be down to new API?

    • https://elie.im Elie Bursztein

      Working on it. The new API requires a lot of change. it is 99% implemented, I will do some testing tomorrow and release the new version.

  • Pingback: Romania

  • Mickey

    That’s great news Elie. It’s a fantastic script and i’m sure all users appreciate what you’ve done.

  • Mickey

    That’s great news Elie. It’s a fantastic script and i’m sure all users appreciate what you’ve done.

Popular blog posts
Latest social News
New survey: 19% of users use their browser private mode - http://t.co/2BTgm6SA #security #privacy #infosec #smo
19% of users use their browser private mode - http://t.co/ed2NqpaZ #security #privacy #infosec
1 day ago
Blizzard fixing GAME Australia's bankruptcy mess, giving Diablo 3 to those who preordered - http://t.co/JjpVm5X5 #d3 #diablo #diablo3
SessionJuggler Secure Web Login from an Untrusted Terminal Using Session Hijacking - http://t.co/IRQsBcVY #security #infosec #www2012...
Fascinating: An interview with a cybercriminal - http://t.co/amO1M5wN < guy operate a 10k botnet. #botnet #security #infosec