我用foursquare-async库与php连接到四个方块。我有两个文件index.php和callback.php。
在我的index.php页面上,代码是
<?php
require_once 'EpiCurl.php';
require_once 'EpiFoursquare.php';
$clientId = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx';
$clientSecret = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx';
$redirectUrl='http://www.example.com/match/4square/callback.php';
$fsObj = new EpiFoursquare($clientId, $clientSecret);
// $redirectUrl is what you specified when creating the application
$url = $fsObj->getAuthorizeUrl($redirectUrl);
echo "<a href=\"$url}\">Click here";
?>
<?php
require_once 'EpiCurl.php';
require_once 'EpiFoursquare.php';
$clientId = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx';
$clientSecret = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx';
$redirectUrl='http://www.example.com/match/4square/callback.php';
$fsObj = new EpiFoursquare($clientId, $clientSecret);
// exchange the request token for an access token
$token = $fsObj->getAccessToken($_GET['code'], $redirectUrl);
// you can store $token->access_token in your database
$fsObj->setAccessToken($token->access_token);
$fsObj->setAccessToken($token->access_token);
$badges = $fsObj->get('/users/self/badges');
echo "<pre>";
print_r($badges);
echo "</pre>";
?>
http://www.example.com/match/4square/callback.php%7D?code=xxxxxxxxxxxxxxxxxxxxxxxxx
The requested URL /match/4square/callback.php} was not found on this server. Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request.
Fatal error: Uncaught exception 'EpiFoursquareBadRequestException'
with message '{ "error":"invalid_grant" }' in
/home/cpantryc/public_html/match/4square/EpiFoursquare.php:244 Stack trace:
#0 /home/cpantryc/public_html/match/4square/EpiFoursquare.php(208):
EpiFoursquareException::raise(Object(EpiCurlManager), false) #1
/home/cpantryc/public_html/match/4square/callback.php(14): EpiFoursquareJson->
__get('access_token') #2 {main} thrown in
/home/cpantryc/public_html/match/4square/EpiFoursquare.php on line 244
我的问题是我出错了。