Skip to content

Instantly share code, notes, and snippets.

@sapegin
Created May 30, 2012 15:28
Show Gist options
  • Select an option

  • Save sapegin/2837028 to your computer and use it in GitHub Desktop.

Select an option

Save sapegin/2837028 to your computer and use it in GitHub Desktop.
Simple Foursquare last checkin proxy
<?php
/**
* Foursquare last checkin proxy
*
* Setup:
* Create file .token with your OAuth token. (You can get it here: https://elie.im/foursquare)
*
* Usage:
* //example.com/whereami.php?callback=func
*
* @author Artem Sapegin
* @copyright 2012 Artem Sapegin (sapegin.me)
* @license MIT
*/
function get_last_checkin() {
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_HTTPHEADER => array('Content-type: application/json'),
CURLOPT_RETURNTRANSFER => true,
CURLOPT_SSL_VERIFYPEER => false,
CURLOPT_URL => 'https://api.foursquare.com/v2/users/self/checkins?limit=1&oauth_token=' . OAUTH_TOKEN . '&v=' . date('Ymd')
));
$result = curl_exec($curl);
curl_close($curl);
if ($result) {
return $result;
}
return false;
}
define('OAUTH_TOKEN', file_get_contents('.token'));
if (!OAUTH_TOKEN || empty($_GET['callback'])) {
header('HTTP/1.0 400 Bad request');
exit();
}
header('Content-type: application/x-javascript; charset=UTF-8');
print $_GET['callback'] . "('" . get_last_checkin() . "')";
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment