GetPrivate
Performs a request for a private resource
public GetPrivate ( String $endpoint, Array $params = false, boolean $POST = 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) |
$POST | boolean | whether or not to use a POST request |
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; }
?> </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 foreach ($users->response->results as $user) { ?> <li> <?php if (property_exists($user, "firstName")) {