Reputation: 94
I'm trying to get my access token from trakt.tv. I get the authorization code and, as the documentation says I do:
$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);
However, the response is empty. What am I doing wrong?
Upvotes: 0
Views: 320
Reputation: 2174
You need to set the request header. Try
$header = array("Content-type: application/json",
"trakt-api-key: yourclientkeyhere",
"trakt-api-version: 2"
);
curl_setopt($ch,CURLOPT_HTTPHEADER, $header);
Upvotes: 1