function location_4sq_search($query, $cats = array(), $limit = 50) { $foursquare = new FoursquareApi(FOUR_SQ_API_KEY, FOUR_SQ_API_SECRET); $params = array('query' => $query, 'intent' => 'global', 'limit' => $limit); $user = new User(); if (is_object($user->last_location)) { $params['ll'] = $user->last_location->coords->latitude . ', ' . $user->last_location->coords->longitude; unset($params['intent']); } $response = json_decode($foursquare->GetPublic('venues/search', $params)); if (count($response->response->venues) == 0) { unset($params['ll']); $params['intent'] = 'global'; $response = json_decode($foursquare->GetPublic('venues/search', $params)); } if (!empty($cats)) { foreach ($response->response->venues as &$v) { $remove = true; foreach ($v->categories as $c) { foreach ($cats as $cat) { if ($cat == $c->id) { $remove = false; } } } if ($remove) { unset($v); } } } return $response; }
/** * Constructor * */ public function __construct($sVersion = 'v2', $sLanguage = 'en', $sApiVersion = '20140104') { $cfgFile = parse_ini_file("/aux0/WhoIsInTheLab/db.cfg", true); $config = isset($cfgFile['FOURSQUARE']) ? $cfgFile['FOURSQUARE'] : array(); $this->m_sVenueId = isset($config['venue']) ? $config['venue'] : false; $this->m_nRefreshRate = isset($config['checkinPeriod']) ? $config['checkinPeriod'] : 24; $sClientId = isset($config['key']) ? $config['key'] : false; $sClientSecret = isset($config['secret']) ? $config['secret'] : false; $sRedirectUrl = isset($config['url']) ? $config['url'] : false; parent::__construct($sClientId, $sClientSecret, $sRedirectUrl, $sVersion, $sLanguage, $sApiVersion); }
/** * Return array of recent checkins to foursquare * @param integer|null $id * @param integer $limit * @return type */ public function getRecentCheckins($id = null, $params = array(), $requestOpts = array()) { $params = array_merge($params, array('limit' => 10)); if (null === $id) { if (null === parent::getAuthClientId()) { new \Exception('You must supply a valid user id either via a config file or in the method call.'); } return $this->get('users/' . parent::getAuthClientId() . '/checkins', $params, $requestOpts); } return $this->get('users/' . $id . '/checkins', $params, $requestOpts); }
function mb_get_latest_foursquare_location() { require_once 'inc/FoursquareApi.php'; $foursquare = new FoursquareApi(FOURSQUARE_ACCESS, FOURSQUARE_SECRET); $foursquare->SetAccessToken(FOURSQUARE_USER_TOKEN); $user = $foursquare->GetPrivate("users/self/checkins"); $data = json_decode($user); if ($data->meta->code !== 200) { return false; } $city = $data->response->checkins->items[0]->venue->location->city; $state = $data->response->checkins->items[0]->venue->location->state; $country = $data->response->checkins->items[0]->venue->location->country; $location = ""; if ($city) { $location .= $city; } if ($state) { $location .= ', ' . $state; } if ($country && $country !== "United States") { $location .= $country; } return $location; }
<?php require_once "../src/FoursquareApi.class.php"; // This file is intended to be used as your redirect_uri for the client on Foursquare // Set your client key and secret $client_key = "<your client key>"; $client_secret = "<your client secret>"; $redirect_uri = "<your redirect uri>"; // Load the Foursquare API library $foursquare = new FoursquareApi($client_key, $client_secret); // If the link has been clicked, and we have a supplied code, use it to request a token if (array_key_exists("code", $_GET)) { $token = $foursquare->GetToken($_GET['code'], $redirect_uri); } ?> <!doctype html> <html> <head> <title>PHP-Foursquare :: Token Request Example</title> </head> <body> <h1>Token Request Example</h1> <p> <?php // If we have not received a token, display the link for Foursquare webauth if (!isset($token)) { echo "<a href='" . $foursquare->AuthenticationLink($redirect_uri) . "'>Connect to this app via Foursquare</a>"; // Otherwise display the token } else { echo "Your auth token: {$token}"; }
<input type="text" name="name" /> <input type="submit" value="Search!" /> </form> <p>Searching for users with name similar to <?php echo $name; ?> </p> <hr /> <?php // Set your client key and secret $client_key = "<your client key>"; $client_secret = "<your client secret>"; // Set your auth token, loaded using the workflow described in tokenrequest.php $auth_token = "<your auth token>"; // Load the Foursquare API library $foursquare = new FoursquareApi($client_key, $client_secret); $foursquare->SetAccessToken($auth_token); // Prepare parameters $params = array("name" => $name); // Perform a request to a authenticated-only resource $response = $foursquare->GetPrivate("users/search", $params); $users = json_decode($response); // NOTE: // Foursquare only allows for 500 api requests/hr for a given client (meaning the below code would be // a very inefficient use of your api calls on a production application). It would be a better idea in // this scenario to have a caching layer for user details and only request the details of users that // you have not yet seen. Alternatively, several client keys could be tried in a round-robin pattern // to increase your allowed requests. ?> <ul> <?php
$foursquare = new FoursquareApi($client_key, $client_secret); // Prepare parameters $params = array("ll" => "{$lat},{$lng}", "query" => "{$q}"); // Perform a request to a public resource $response = $foursquare->GetPublic("venues/" . $type, $params); $app->response()->header("Content-Type", "application/json"); echo $response; }); // GET Venue Detail $app->get('/venue/:id', function ($id) use($app) { global $near_config; require_once "Slim/Helper/FoursquareApi.php"; // Set your client key and secret $client_key = $near_config['client_key']; $client_secret = $near_config['client_secret']; $foursquare = new FoursquareApi($client_key, $client_secret); // Perform a request to a public resource $response = $foursquare->GetPublic("venues/" . $id); $app->response()->header("Content-Type", "application/json"); echo $response; }); //save venue $app->post('/savevenue', function () use($app) { session_start(); $response = array(); $r = json_decode($app->request->getBody()); $r->foursquare_id = $venId = $r->venId; $r->name = $venName = $r->venName; $r->user_id = $user_id = $_SESSION['nc_uid']; $table_name = "venue"; $near_db = new near_query_handler();
<?php require_once "../src/FoursquareApi.class.php"; // Set your client key and secret $client_key = ""; $client_secret = ""; // Load the Foursquare API library if ($client_key == "" or $client_secret == "") { echo 'Load client key and client secret from <a href="https://developer.foursquare.com/">foursquare</a>'; exit; } $foursquare = new FoursquareApi($client_key, $client_secret); $location = array_key_exists("location", $_GET) ? $_GET['location'] : "Montreal, QC"; ?> <!doctype html> <html> <head> <title>PHP-Foursquare :: Unauthenticated Request Example</title> <style> div.venue { float: left; padding: 10px; background: #efefef; height: 90px; margin: 10px; width: 340px; } div.venue a { color:#000;