jwilsson / spotify-web-api-php

A PHP wrapper for Spotify's Web API.
MIT License
862 stars 156 forks source link

Recover images in search #201

Closed DarKl4ne closed 4 years ago

DarKl4ne commented 4 years ago

Hello

I wanted to know how we can get the address of the image when we do an album search. I tried but still have an array error. So i can't do it

thank you for your help

adamazad commented 4 years ago

Can you post the code snippet for it?

DarKl4ne commented 4 years ago

Here is the display for research

foreach ($results->albums->items as $album) {
    //echo 'Titre: '.$album->images, '<br>';
    echo 'Titre: '.$album->name, '<br>';
    echo 'Date: '.$album->release_date, '<br>';
    echo 'Nombre de piste: '.$album->total_tracks, '<br>';
    echo $album['images']['1']->url;
}

Dans l'adresse api les images sont déjà dans array qui est items

[items] => Array
                (
**"Information that I collect"**
[images] => Array
                                (
                                    [0] => stdClass Object
                                        (
                                            [height] => 640
                                            [url] => https://i.scdn.co/image/ab67616d0000b273614c5f63afef27e4dfa9f596
                                            [width] => 640
                                        )

                                    [1] => stdClass Object
                                        (
                                            [height] => 300
                                            [url] => https://i.scdn.co/image/ab67616d00001e02614c5f63afef27e4dfa9f596
                                            [width] => 300
                                        )

                                    [2] => stdClass Object
                                        (
                                            [height] => 64
                                            [url] => https://i.scdn.co/image/ab67616d00004851614c5f63afef27e4dfa9f596
                                            [width] => 64
                                        )

                                )

So I would like to know how to retrieve information from an array which is already in an array

thank you

adamazad commented 4 years ago

$album is a stdClass, so try:

$album->images['1']->url;
DarKl4ne commented 4 years ago

Thank you very much it works

I was not far away I had done like this echo $album['images']['1']->url;

jwilsson commented 4 years ago

Glad you got it working!

And thanks @adamazad for helping out!