使用PHP的foursquare身份验证问题

时间:2011-04-07 10:56:25

标签: php authentication oauth foursquare


我用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";
  ?>

在我的callback.php页面上,代码为
<?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>";
  ?>

1:当我从foursquare登录并将应用程序改为时,它将我重定向到此页面时出现错误
http://www.example.com/match/4square/callback.php%7D?code=xxxxxxxxxxxxxxxxxxxxxxxxx

注意:查看%&amp; D(它是在callback.php之后关闭大括号'}')。这会生成错误
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.

2:当我删除花括号时,它会产生此错误
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

我的问题是我出错了。

0 个答案:

没有答案