GetToken() 공개 메소드

GetToken Performs a request to Foursquare for a user token, and returns the token, while also storing it locally for use in private requests
public GetToken ( $code, $redirect = '' )
$code The 'code' parameter provided by the Foursquare webauth callback redirect
$redirect The configured redirect_uri for the provided client credentials
예제 #1
0
<?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}";
}