Posted on November 17, 2010 at 2:05 am

Foursquare API for Java Applications

API for JAVA

Hello!, today I am going to be presenting a new small project called foursquared-desktop-api about an API that lets you interact with FourSquare.com . This project that takes advantage the work made by the authors of  foursquared , an excelent opensouce mobile app, originally made for android. I decided to release a Java version since I could not find anything like this arond.

Some of the best features are…

  • Complete class model of foursquare objects and messages.
  • Json parsers for all the messages.
  • Version #1 of the api is supported.
  • It identifies as a mobile app (by default)
  • Nice and clean coding.
  • Able to use both Http and Oauth.

Project Summary:

That’s all folks by now! Next time I probably will be introducing some of the work I am doing with this API.

Thanks for reading and feel free to send me any comments. Below I pasted a short Junit (sample code) with basic usage of this api.

Sample Usage :

  1. package com.lemil.forsquares.server.foursquare.api;
  2. import junit.framework.TestCase;
  3. import org.json.JSONObject;
  4. import com.lemil.forsquares.api.foursquare.FoursquareApi.Location;
  5. import com.lemil.forsquares.api.foursquare.types.Checkin;
  6. import com.lemil.forsquares.api.foursquare.types.CheckinResult;
  7. import com.lemil.forsquares.api.foursquare.types.Group;
  8. import com.lemil.forsquares.server.ForSquaresServiceImpl;
  9. public class ForSquaresServiceTest extends TestCase   {
  10. String phoneNumber = “phonenumber”;
  11. String password = “passowrd”;
  12. String geolat = “-34.488483210361125″;
  13. String geolong = “-58.52286100387573″;
  14. ForSquaresServiceImpl service = null;
  15. public ForSquaresServiceTest() {
  16. }
  17. protected void setUp() throws Exception {
  18. super.setUp();
  19. service = new ForSquaresServiceImpl(phoneNumber, password);
  20. service.loadApi();
  21. }
  22. public void testLogin(){
  23. try {
  24. boolean b = service.isApiLoaded();
  25. assert(b);
  26. } catch(Exception e) {
  27. e.printStackTrace();
  28. assert(false);
  29. }
  30. }
  31. //Group<Checkin> getRecentCheckinsFromFriends() throws IllegalArgumentException ;
  32. public void testGetRecentCheckinsFromFriends(){
  33. try {
  34. Location location = new Location(geolat, geolong);
  35. Group<Checkin> fc = service.getRecentCheckinsFromFriends(location);
  36. for(Checkin c : fc) {
  37. JSONObject o  = new JSONObject(c);
  38. System.out.println(o.toString());
  39. }
  40. assert(true);
  41. } catch(Exception e) {
  42. e.printStackTrace();
  43. assert(false);
  44. }
  45. }
  46. //CheckinResult checkin(String input) throws IllegalArgumentException;
  47. public void testCheckin(){
  48. try {
  49. String venueId = “2201505″;
  50. String venueName = “Starbucks”;
  51. Location location = new Location(“-34.54567867050709″, “-58.48865747451782″);
  52. String shout = null;
  53. boolean isPrivate = true;
  54. boolean tellFollowers = false;
  55. boolean twitter = false;
  56. boolean facebook = false;
  57. CheckinResult c = service.checkin(venueId, venueName, location, shout, isPrivate, tellFollowers, twitter, facebook);
  58. JSONObject o  = new JSONObject(c);
  59. System.out.println(o.toString());
  60. assert(true);
  61. } catch(Exception e) {
  62. e.printStackTrace();
  63. assert(false);
  64. }
  65. }

Leave a Reply

About

Twitter Feed