2017-01-21 3 views
0

Ich versuche, mein Zugriffs-Token von trakt.tv zu bekommen. ich den Autorisierungscode, und wie die Dokumentation sagt ich:Leere Antwort curl trakt api

 $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); 

jedoch die Antwort leer ist. Was mache ich falsch?

+0

welchen Wert Sie in $ code buchen? –

+0

Es ist der Code, den ich bekomme, wenn ich die Anwendung autorisiere. Grundsätzlich bekomme ich diesen Code und ich muss ihn mit dem Access Token "austauschen". http://docs.trakt.apiary.io/#reference/authentication-oauth/authorize/exchange-code-for-access_token?console=1 – Dani

Antwort

0

Sie müssen den Anforderungsheader festlegen. Versuchen Sie,

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

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