javascripthtmldeezer

Deezer API Simple Request


I simply want to request information on the albums of a particular artist, but I cannot get the Deezer API to work for me. I've tried importing the SDK and calling DZ.api like it says to in the docs:

<script src="https://e-cdns-files.dzcdn.net/js/min/dz.js"></script>
<script>
DZ.api("/artist/15030/albums", function(response) {
    console.log(response);
});
</script>

And I've tried using a script tag to make the request (jsonp):

<script>
window.populateDiscography = function(response) {
    console.log(response);
}
</script>
<script src="https://api.deezer.com/artist/15030/albums?callback=window.populateDiscography" type="application/json"></script>

The first one errors out with:

document.getElementById(...) is null dz.js:2:1792894

_send@https://e-cdns-files.dzcdn.net/js/min/dz.js:2:131967
apiCall@https://e-cdns-files.dzcdn.net/js/min/dz.js:2:1019990
buQ+/t.a/e.api@https://e-cdns-files.dzcdn.net/js/min/dz.js:2:1019526
@http://localhost:8000/index.php:33:7
dz.js:2:1792919

And the second does not seem to call the callback or indeed show up in the Network tab in dev tools (no response?)

Am I missing something? I don't want to use authentication but do I have to?

Any help would be much appreciated, thanks

I'm testing on localhost on Firefox.


Solution

  • Okay I got it working I was being stupid, the JSONP request to the deezer API returns JS, a function call to the callback specified, with the returned JSON as the argument, it doesn't return pure JSON.

    So what works is:

    <script>
    function populateDiscography(response) {
        console.log(response);
    }
    </script>
    <script src="https://api.deezer.com/artist/15030/albums?callback=populateDiscography"></script>