Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
A small script to show who is the Mayor of a Foursquare Venue on your site.
<?php
//main function
function foursquare_spotter() {
//set SpotID and Oauth Token - https://foursquare.com/oauth/
$spot_id = 311661; // just change this # to your venue # in the foursquare URL
$oauth_token = 123456789; // just change this # to your Oauth Token
if ($spot_id != "") {
$ch = curl_init();
// set URL and other appropriate options
curl_setopt($ch, CURLOPT_URL, "https://api.foursquare.com/v2/venues/$spot_id?oauth_token=$oauth_token");
curl_setopt($ch,CURLOPT_HTTPHEADER, array ("Content-Type: application/json;charset=utf-8","Accept: application/json"));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HEADER, 0);
// grab URL and store it
$json = curl_exec($ch);
// close cURL resource, and free up system resources
curl_close($ch);
//decode json array
$json = json_decode($json);
//print headline with appropriate links
$place = $json->response->venue->name;
$mayor = $json->response->venue->mayor->user->firstName;
$mayorphoto = $json->response->venue->mayor->user->photo;
$output = "";
$output .= "The Current Mayor is <br /><img src=\" " . $mayorphoto . "\" style=\"padding:5px; width:25px; vertical-align: middle;\"><span style=\"padding:5px; font-size: 18px; font-weight:bold;\">" . $mayor . "</span>";
}
//print_r($json);
echo $output;
}
if (function_exists('foursquare_spotter')) foursquare_spotter();
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.