E. Foursquare

  1. Authentication
  2. Campaign
  3. Checkins
  4. Events
  5. List
  6. Pages
  7. Page Updates
  8. Photos
  9. Settings
  10. Specials
  11. Tips
  12. Updates
  13. Users
  14. Venue
  15. Venue Groups


The first thing we want to do is get an client ID and client secret. This can be acheived by visiting Foursquare's My Apps and creating a new app or using an existing one. We can next plug in both of those to start an authentication process as in Figure 1.And dont forget to replace http://yourwebsite.com/auth with the URL of your website and page you will be handling the Facebook authentication.

Figure 1. Instantiate Auth
$auth = eden('foursquare')->auth('[FOURSQUARE_ID]', '[FOURSQUARE_SECRET]', 'http://yourwebsite.com/auth');

With this auth class let's make sure we can generate a login URL. Figure 2 is used to redirect the user to foursquare to continue the authentication.

Figure 2. Get Login URL
$login = $auth->getLoginUrl();

When the user has authorized our app to use their data, Four Square will add an auth code, we can use to transfer to an access token. Figure 3 shows how we can convert that auth code to a token.

Figure 3. Get Token
$access = $auth->getAccess($_GET['code']);
$_SESSION['token'] = $access['access_token'];

An example of the whole entire authentication process can be found in Figure 4.

Figure 4. Authentication

$auth = eden('foursquare')->auth('[FOURSQUARE_ID]', '[FOURSQUARE_SECRET]', 'http://yourwebsite.com/auth');

//if no code and no session
if(!isset($_GET['code']) && !isset($_SESSION['token'])) {
    //redirect to login
    $login = $auth->getLoginUrl();
    header('Location: '.$login);

//Code is returned back from foursquare
if(isset($_GET['code'])) {
    //save it to session
	$access = $auth->getAccess($_GET['code'])
    $_SESSION['token'] = $access['access_token'];

© 2012 Openovate Labs. All rights reserved.