空响应卷曲trakt api

时间:2017-01-21 09:13:48

标签: php curl

我正在尝试从trakt.tv获取访问令牌。 我得到了授权码,正如文档所说:

        $ch = curl_init();
        $code = $_GET['code'];
        $data = array(
          "code"=>$code, 
          "client_id"=>"my client id",
          "client_secret"=>"my client secret",
          "redirect_uri"=>"my redirect url",
          "grant_type"=>"authorization_code"
        );
        curl_setopt($ch,CURLOPT_URL, "https://trakt.tv/oauth/token");
        curl_setopt($ch,CURLOPT_RETURNTRANSFER, TRUE);
        curl_setopt($ch,CURLOPT_HEADER, FALSE);
        curl_setopt($ch,CURLOPT_POST, TRUE);
        curl_setopt($ch,CURLOPT_POSTFIELDS, $data);
        curl_setopt($ch,CURLOPT_HTTPHEADER, array(
          "Content-Type: application/json"
        ));
        $response = curl_exec($ch);
        curl_close($ch);
        var_dump($response);

但是,回复是空的。 我做错了什么?

1 个答案:

答案 0 :(得分:0)

您需要设置请求标头。试试

$header = array("Content-type: application/json",
                "trakt-api-key: yourclientkeyhere",
                "trakt-api-version: 2"

               );
curl_setopt($ch,CURLOPT_HTTPHEADER, $header);