I'm a learning IT student. I'm trying to use the Deezer API to edit playlists on another web site. I cannot get a correct connection to a Deezer account and get this error (with the official Deezer code example):
Warning:
file_get_contents(https://connect.deezer.com/oauth/access_token.php?app_id=...&secret=...&code=...): failed to open stream: HTTP request failed! HTTP/1.0 403 Forbidden in /home///music/index.php on line 44
Code PHP used to create the connection:
<?php
$app_id = ...;
$app_secret = "...";
$my_url = "https://music._.fr/index.php";
session_start();
$code = $_REQUEST["code"];
if(empty($code)){
$_SESSION['state'] = md5(uniqid(rand(), TRUE)); //CSRF protection
$dialog_url = "https://connect.deezer.com/oauth/auth.php?app_id=".$app_id
."&redirect_uri=".urlencode($my_url)."&perms=email,offline_access"
."&state=". $_SESSION['state'];
header("Location: ".$dialog_url);
exit;
}
if($_REQUEST['state'] == $_SESSION['state']) {
$token_url = "https://connect.deezer.com/oauth/access_token.php?app_id="
.$app_id."&secret="
.$app_secret."&code=".$code;
$response = file_get_contents($token_url);
$params = null;
parse_str($response, $params);
$api_url = "https://api.deezer.com/user/me?access_token="
.$params['access_token'];
$user = json_decode(file_get_contents($api_url));
echo("Hello " . $user->name);
}else{
echo("The state does not match. You may be a victim of CSRF.");
}
?>
If you could please explain why this code isn't working correctly knowing that I set my Deezer API settings correctly (I think).