0

Foursquare API 呼び出しにphp-foursquareライブラリを使用しています。

これは私の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 server error を返します。これは 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;
    }
4

2 に答える 2

1

私は php-foursquare を使用していませんが、Guzzle を使用して 4sq REST エンドポイントに接続するときに同様の問題に直面しました。

リクエストを try catch ブロックでラップせずに 200 ヘッダーとは異なるものを取得すると、未処理の例外が発生することが判明しました。なぜエラー 500 が発生したのか理解できませんでしたが、例外をキャプチャして印刷すると、Foursquare が 401 を返し、さらに有益なメッセージが表示されました。私の場合、リダイレクト URL にタイプミスがありました。

try {
$result = $this->GET($this->TokenUrl,$params);
} catch (Exception $e) {
 echo $e->getMessage();
}    
于 2013-07-31T22:47:35.690 に答える
0

さて、ここで問題です。4square のサーバーを制御することはできないため、推測せずにこれを行うには十分な情報がありません。私は2つのことをします:

  1. 使用している API 呼び出しを Google で検索し、一般的な回答で一般的な問題かどうかを確認します
  2. 4square にメールを送信 - サーバーが有用な情報を含まないエラー メッセージを吐き出しているためです。
于 2011-07-14T22:30:27.557 に答える