繁体   English   中英

使用 Foursquare API 时出现 500 服务器错误

[英]500 Server Error When Using Foursquare API

我正在为 Foursquare API 调用使用php-foursquare库。

这是我的索引。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;
    }

我没有使用 php-foursquare,但在使用 Guzzle 连接到 4sq REST 端点时遇到了类似的问题。

事实证明,如果您不将请求包装在 try catch 块中,并且它会得到与 200 header 不同的任何内容,则该请求将导致未处理的异常。 我不明白为什么我会收到错误 500,但是当我捕获并打印异常时,它显示 Foursquare 返回了一个 401 并带有更多信息的消息。 就我而言,重定向 URL 有错字。

try {
$result = $this->GET($this->TokenUrl,$params);
} catch (Exception $e) {
 echo $e->getMessage();
}    

好吧,这就是问题所在。 您对 4square 的服务器没有任何控制权,因此您没有足够的信息向 go 提供这方面的信息,无需猜测。 我会做两件事:

  1. 谷歌你正在使用的 API 电话,看看这是否是常见问题的常见问题
  2. Email 4square - 这是他们的服务器吐出没有有用信息的错误消息。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM