SetAccessToken() public method

SetAccessToken Basic setter function, provides an authentication token to GetPrivate requests
public SetAccessToken ( String $token )
$token String A Foursquare user auth_token
Esempio n. 1
0
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;
}
		<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 
foreach ($users->response->results as $user) {