GetPublic() 공개 메소드

GetPublic Performs a request for a public resource
public GetPublic ( String $endpoint, Array $params = false )
$endpoint String A particular endpoint of the Foursquare API
$params Array A set of parameters to be appended to the request, defaults to false (none)
예제 #1
0
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;
}
예제 #2
0
    $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();
    $isVenueSaved = $near_db->getOneRecord("select 1 from " . $table_name . " where foursquare_id='" . $venId . "' and user_id='" . $user_id . "'");
    if (!$isVenueSaved) {
예제 #3
0
	<form action="" method="GET">
		<input type="text" name="location" />
		<input type="submit" value="Search!" />
	</form>
<p>Searching for venues near <?php 
echo $location;
?>
</p>
<hr />
<?php 
// Generate a latitude/longitude pair using Google Maps API
list($lat, $lng) = $foursquare->GeoLocate($location);
// Prepare parameters
$params = array("ll" => "{$lat},{$lng}");
// Perform a request to a public resource
$response = $foursquare->GetPublic("venues/search", $params);
$venues = json_decode($response);
?>
	
		<?php 
foreach ($venues->response->venues as $venue) {
    ?>
			<div class="venue">
				<?php 
    if (isset($venue->categories['0'])) {
        echo '<image class="icon" src="' . $venue->categories['0']->icon->prefix . '88.png"/>';
    } else {
        echo '<image class="icon" src="https://foursquare.com/img/categories/building/default_88.png"/>';
    }
    echo '<a href="https://foursquare.com/v/' . $venue->id . '" target="_blank"/><b>';
    echo $venue->name;