bonjour,

petit problème au niveau du code sur un tuto pour lastfm

je voudrait mettre en place L' API LastFM pour mettre en place un système qui vous permettra d'afficher les dernières musiques que vous avez écoutées, le problème c'est qu'il m'affiche une page blanche et j'ai pas les titres, les infos (UID) et (APIKEY) de ma radio ne sont pas relayées au script pourquoi ?

http://ftsradio.legtux.org/lastfm/

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="fr" lang="fr">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <link rel="stylesheet" href="css/style.css">
    <title>Ftsradio - last.fm</title>
    </head>
    <body>      

        <?php
        require 'lastFM.php';
        $lastfm = new LastFM($apiKey);
        $tracks = $lastfm->getRecentTracks('ftsradio');
        ?>
        <div class="wrap">
            <h1>Inspiré par <a href="http://ftsradio.legtux.org">SEM</a></h1>
            <ul class="playlist">
                <?php foreach($tracks as $k=>$v): ?>
                    <li>
                        <a href="<?php echo $v->artist; ?>">
                            <img src="<?php echo $v->image[0]; ?>" alt="">
                            <span class="disc"></span>
                            <span class="info">
                                <span class="artist"><?php echo $v->artist; ?></span>
                                <span class="name"><?php echo $v->name; ?></span>
                            </span>
                        </a>
                    </li>
                <?php endforeach; ?>
            </ul>
        </div>

    </body>
</html>

ps : je donnerai pas L'autre fichier avec mon apikey DSL

9 réponses


sem95
Auteur

up

Bonjour, tenter un var_dump des tracks soit :

<?php
var_dump($tracks);

.

Cordialement.

sem95
Auteur

il me met ca :

object(SimpleXMLElement)#3 (2) { "@attributes"]=> array(5) { "user"]=> string(8) "ftsradio" "page"]=> string(1) "1" "perPage"]=> string(2) "10" "totalPages"]=> string(1) "1" "total"]=> string(1) "2" } "track"]=> array(2) { [0]=> object(SimpleXMLElement)#4 (8) { "artist"]=> string(32) "Rhythms Del Mundo Feat. Coldplay" "name"]=> string(12) "Viva La Vida" "streamable"]=> string(1) "0" "mbid"]=> string(36) "f97d99ca-be84-46e3-8ed3-a2c72a578f84" "album"]=> string(25) "Rhythms Del Mundo: Africa" "url"]=> string(72) "http://www.last.fm/music/Rhythms+Del+Mundo+Feat.+Coldplay/_/Viva+La+Vida" "image"]=> array(4) { [0]=> string(50) "http://userserve-ak.last.fm/serve/34s/87834643.png" [1]=> string(50) "http://userserve-ak.last.fm/serve/64s/87834643.png" [2]=> string(50) "http://userserve-ak.last.fm/serve/126/87834643.png" [3]=> string(54) "http://userserve-ak.last.fm/serve/300x300/87834643.png" } "date"]=> string(18) "27 Sep 2014, 17:48" } [1]=> object(SimpleXMLElement)#5 (8) { "artist"]=> string(8) "Coldplay" "name"]=> string(19) "A Sky Full of Stars" "streamable"]=> string(1) "0" "mbid"]=> string(36) "21a17652-d4c5-4403-bff4-2715e7c60022" "album"]=> string(13) "Ghost Stories" "url"]=> string(55) "http://www.last.fm/music/Coldplay/_/A+Sky+Full+of+Stars" "image"]=> array(4) { [0]=> string(50) "http://userserve-ak.last.fm/serve/34s/99319661.png" [1]=> string(50) "http://userserve-ak.last.fm/serve/64s/99319661.png" [2]=> string(50) "http://userserve-ak.last.fm/serve/126/99319661.png" [3]=> string(54) "http://userserve-ak.last.fm/serve/300x300/99319661.png" } "date"]=> string(18) "27 Sep 2014, 17:39" } } }

c'est bon signe il prend en compte les music pris

sem95
Auteur

par contre j'ai une question il prend en compte l'api de lastfm mais peut t'on mettre mon api lié a ma webradio ?

Bonsoir, voilà le tableaux en plus claire :

object(SimpleXMLElement)#3 (2) { 
    "@attributes"]=> array(5) { 
        "user"]=> string(8) "ftsradio" 
        "page"]=> string(1) "1" 
        "perPage"]=> string(2) "10" 
        "totalPages"]=> string(1) "1" 
        "total"]=> string(1) "2" 
    } 
    "track"]=> array(2) { 
        [0]=> object(SimpleXMLElement)#4 (8) { 
            "artist"]=> string(32) "Rhythms Del Mundo Feat. Coldplay" 
            "name"]=> string(12) "Viva La Vida" 
            "streamable"]=> string(1) "0" 
            "mbid"]=> string(36) "f97d99ca-be84-46e3-8ed3-a2c72a578f84" 
            "album"]=> string(25) "Rhythms Del Mundo: Africa" 
            "url"]=> string(72) "http://www.last.fm/music/Rhythms+Del+Mundo+Feat.+Coldplay/_/Viva+La+Vida" 
            "image"]=> array(4) { 
                [0]=> string(50) "http://userserve-ak.last.fm/serve/34s/87834643.png" [1]=> string(50) "http://userserve-ak.last.fm/serve/64s/87834643.png" 
                [2]=> string(50) "http://userserve-ak.last.fm/serve/126/87834643.png" 
                [3]=> string(54) "http://userserve-ak.last.fm/serve/300x300/87834643.png" 
            } 
            "date"]=> string(18) "27 Sep 2014, 17:48" 
        } 
        [1]=> object(SimpleXMLElement)#5 (8) { 
            "artist"]=> string(8) "Coldplay" 
            "name"]=> string(19) "A Sky Full of Stars" 
            "streamable"]=> string(1) "0" 
            "mbid"]=> string(36) "21a17652-d4c5-4403-bff4-2715e7c60022" 
            "album"]=> string(13) "Ghost Stories" 
            "url"]=> string(55) "http://www.last.fm/music/Coldplay/_/A+Sky+Full+of+Stars" 
            "image"]=> array(4) { 
                [0]=> string(50) "http://userserve-ak.last.fm/serve/34s/99319661.png" 
                [1]=> string(50) "http://userserve-ak.last.fm/serve/64s/99319661.png" 
                [2]=> string(50) "http://userserve-ak.last.fm/serve/126/99319661.png" 
                [3]=> string(54) "http://userserve-ak.last.fm/serve/300x300/99319661.png" 
            } 
            "date"]=> string(18) "27 Sep 2014, 17:39" } 
    } 
}

Donc vous souhaiter les derniers "tracks" écouté et donc voici

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="fr" lang="fr">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <link rel="stylesheet" href="css/style.css">
    <title>Ftsradio - last.fm</title>
    </head>
    <body>      

        <?php
        require 'lastFM.php';
        $lastfm = new LastFM($apiKey);
        $tracks = $lastfm->getRecentTracks('ftsradio');
        $track_list = $tracks"track"];
        ?>
        <div class="wrap">
            <h1>Inspiré par <a href="http://ftsradio.legtux.org">SEM</a></h1>
            <ul class="playlist">
                <?php foreach($track_list as $k=>$v): ?>
                    <li>
                        <a href="<?php echo $v->artist; ?>">
                            <img src="<?php echo $v->image[0]; ?>" alt="">
                            <span class="disc"></span>
                            <span class="info">
                                <span class="artist"><?php echo $v->artist; ?></span>
                                <span class="name"><?php echo $v->name; ?></span>
                            </span>
                        </a>
                    </li>
                <?php endforeach; ?>
            </ul>
        </div>

    </body>
</html>

Oui vous pouvez normalement si je me trompe pas.

Cordialement.

sem95
Auteur

ca marche;

mais j'ai je veut mettre ma clé api de ma radio je connait pas la manip :(

Bonsoir, regardez de ce coter : Ici.

Cordialement.

sem95
Auteur

merci je vais regarder ca :)

Bonsoir, pas de soucis ! :)

Cordialement.