【发布时间】:2011-07-14 22:26:00
【问题描述】:
我正在使用 php-foursquare 库进行 Foursquare API 调用。
这是我的 index.php
require_once("FoursquareAPI.class.php");
$client_key = "blabla";
$client_secret = "blabla";
$redirect_uri = "http://localhost/4kare/index.php";
// ($redirected_uri equals to registered callback url)
// 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)){
// example $_GET['code'] = FJRW1Z5TZ3H0E3Y2WN4Q0UPSH1PEIDADTZDHYKVG32DJTH2E
$token = $foursquare->GetToken($_GET['code'],$redirect_uri);
}
// 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";
}
但是 GetToken() 方法返回 500 服务器错误。这是GetToken()方法的源代码:
public function GetToken($code,$redirect){
$params = array("client_id"=>$this->ClientID,
"client_secret"=>$this->ClientSecret,
"grant_type"=>"authorization_code",
"redirect_uri"=>$redirect,
"code"=>$code);
$result = $this->GET($this->TokenUrl,$params);
$json = json_decode($result);
$this->SetAccessToken($json->access_token);
return $json->access_token;
}
【问题讨论】:
-
我认为你应该做更多的调试。您能与我们分享完整的 CURL 错误和端点 URL 吗?
-
@ahmet alp balkan,请再次检查。
-
这还不够。您应该跟踪 $this->GET 方法等以查看由foursquare 库准备的确切HTTP 查询。 4sq api 已启动并正在运行。问题可能出在您的身份验证逻辑或 php-foursquare 库本身。
-
@ahmet,我不再使用 php-foursquare。我为我的 api 调用编写了一个类,它工作得很好:)
-
是的,正如我告诉你的那样。问题出在图书馆下面。如果该库被广泛使用,您应该报告事件。
标签: php api foursquare