PHP code example of gabrieljmj / deezer-web-api

1. Go to this page and download the library: Download gabrieljmj/deezer-web-api library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

gabrieljmj / deezer-web-api example snippets


use DeezerWebApi\DeezerSession;
use DeezerWebApi\DeezerWebApi;

session_start();

$session = new DeezerSession(getenv('DEEZER_APP_ID'), getenv('DEEZER_APP_SECRET'), getenv('DEEZER_REDIRECT_URI'));

if (empty($_GET['code'])) {
    $state = md5(uniqid(rand(), true));
    $session->setState($state);
    $_SESSION['state'] = $state;
    $perms = ['manage_library'];
    
    header('Location: ' . $session->getAuthUri($perms);
}

$code = $_GET['code'];
$accessToken = $session->getAccessToken($code);
$deezer = new DeezerWebApi();
$deezer->setAccessToken($accessToken); // Or new DeezerWebApi(null, $accessToken);

$me = $deezer->get('user/me');

$me = $deezer->get('user/me');

$response = $deezer->post('user/me/playlists', ['title' => 'PLAYLIST_TITLE']);
get($resource[, array $params = []])
post($resource[, array $params = []])