我正在使用php-foursquare庫進行Foursquare API調用。使用Foursquare API時的500服務器錯誤
這是我的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巴爾幹,請再次檢查。 – Eray
這還不夠。你應該跟蹤$ this-> GET方法等,以查看由foursquare庫準備的確切的HTTP查詢。 4sq api已啓動並正在運行。問題可能出在你的認證邏輯或php-foursquare庫本身。 –