Información de imágenes de Flickr

Código fuente PHP

// 102-CodigoPHP.php
// Versión 1.0 10/12/2017 Juan Manuel Cueva Lovelle. Universidad de Oviedo

#
# crear la URL de la API que se va a llamar
#

$params = array(
    'api_key'	=> '0565634739c78dcdbf56368cb0991f0b',
    'method'	=> 'flickr.photos.getInfo',
    'photo_id'	=> '33289594495',
    'format'	=> 'php_serial',
);

$encoded_params = array();

foreach ($params as $k => $v){

    $encoded_params[] = urlencode($k).'='.urlencode($v);
}

#
# llamar a la API y decodificar la respuesta
#

$url = "https://api.flickr.com/services/rest/?".implode('&', $encoded_params);

$rsp = file_get_contents($url);

$rsp_obj = unserialize($rsp);

echo "<h2>Objeto PHP recibido</h2>";
print ("<pre>");
print_r($rsp_obj);
print ("</pre>");

echo "<h2>Datos recibidos</h2>";
#
# ver los datos de la imagen (o un error)
#

if ($rsp_obj['stat'] == 'ok'){

    $tituloImagen = $rsp_obj['photo']['title']['_content'];
    echo "<p>Título: $tituloImagen"."</p>";

    if (isset($rsp_obj['photo']['tags']['tag'][0]['raw'])){
        $subTituloImagen0 = $rsp_obj['photo']['tags']['tag'][0]['raw'];
        echo "<p>Subtítulo[0]: $subTituloImagen0"."</p>";    
    }

    if (isset($rsp_obj['photo']['tags']['tag'][1]['raw'])){
        $subTituloImagen1 = $rsp_obj['photo']['tags']['tag'][1]['raw'];
        echo "<p>Subtítulo[1]: $subTituloImagen1"."</p>";    
    }

    if (isset($rsp_obj['photo']['tags']['tag'][2]['raw'])){
        $subTituloImagen2 = $rsp_obj['photo']['tags']['tag'][2]['raw'];
        echo "<p>Subtítulo[2]: $subTituloImagen2"."</p>";    
    }

    $autorImagen = $rsp_obj['photo']['tags']['tag'][0]['authorname'];
    echo "<p>Autor: $autorImagen"."</p>";

    $fechaImagen = $rsp_obj['photo']['dates']['taken'];
    echo "<p>Fecha: $fechaImagen"."</p>";

    $URLimagen = $rsp_obj['photo']['urls']['url'][0]['_content'];
    echo "<p>URL: $URLimagen" ."</p>";

    echo "<p>Enlace: <a href = '$URLimagen'>'$tituloImagen'</a></p>";

    $farm_id = $rsp_obj['photo']['farm'];
    $server_id = $rsp_obj['photo']['server'];
    $photo_id = $rsp_obj['photo']['id'];
    $secret_id = $rsp_obj['photo']['secret'];
    // m = "Medium" width="500" height="333"
    $size = 'm';;

    $photo_url = 'http://farm'.$farm_id.'.staticflickr.com/'.$server_id.'/'.$photo_id.'_'.$secret_id.'_'.$size.'.'.'jpg';

    print "<img alt='".$tituloImagen."' src=' ".$photo_url." '>" ;


}else{

    echo "<h3>¡Error al llamar al servicio Web!</h3>";
}

Ejecución del código PHP

Objeto PHP recibido

Array
(
    [photo] => Array
        (
            [id] => 33289594495
            [secret] => 3627181304
            [server] => 2931
            [farm] => 3
            [dateuploaded] => 1488831847
            [isfavorite] => 0
            [license] => 0
            [safety_level] => 0
            [rotation] => 0
            [originalsecret] => eece14864f
            [originalformat] => jpg
            [owner] => Array
                (
                    [nsid] => 12599770@N08
                    [username] => cueva_lovelle
                    [realname] => 
                    [location] => 
                    [iconserver] => 5572
                    [iconfarm] => 6
                    [path_alias] => cuevalovelle
                    [gift] => Array
                        (
                            [gift_eligible] => 1
                            [eligible_durations] => Array
                                (
                                    [0] => year
                                    [1] => month
                                    [2] => week
                                )

                            [new_flow] => 1
                        )

                )

            [title] => Array
                (
                    [_content] => DSC_5107
                )

            [description] => Array
                (
                    [_content] => Tikal
                )

            [visibility] => Array
                (
                    [ispublic] => 1
                    [isfriend] => 0
                    [isfamily] => 0
                )

            [dates] => Array
                (
                    [posted] => 1488831847
                    [taken] => 2016-08-10 11:45:28
                    [takengranularity] => 0
                    [takenunknown] => 0
                    [lastupdate] => 1488831947
                )

            [views] => 189
            [editability] => Array
                (
                    [cancomment] => 0
                    [canaddmeta] => 0
                )

            [publiceditability] => Array
                (
                    [cancomment] => 1
                    [canaddmeta] => 0
                )

            [usage] => Array
                (
                    [candownload] => 1
                    [canblog] => 0
                    [canprint] => 0
                    [canshare] => 1
                )

            [comments] => Array
                (
                    [_content] => 0
                )

            [notes] => Array
                (
                    [note] => Array
                        (
                        )

                )

            [people] => Array
                (
                    [haspeople] => 0
                )

            [tags] => Array
                (
                    [tag] => Array
                        (
                            [0] => Array
                                (
                                    [id] => 12506957-33289594495-15531
                                    [author] => 12599770@N08
                                    [authorname] => cueva_lovelle
                                    [raw] => Tikal
                                    [_content] => tikal
                                    [machine_tag] => 0
                                )

                        )

                )

            [location] => Array
                (
                    [latitude] => 17.222352
                    [longitude] => -89.623473
                    [accuracy] => 16
                    [context] => 0
                    [locality] => Array
                        (
                            [_content] => Tikal
                            [woeid] => 86457
                        )

                    [county] => Array
                        (
                            [_content] => Flores
                            [woeid] => 26807062
                        )

                    [region] => Array
                        (
                            [_content] => Peten
                            [woeid] => 2345563
                        )

                    [country] => Array
                        (
                            [_content] => Guatemala
                            [woeid] => 23424834
                        )

                    [neighbourhood] => Array
                        (
                            [_content] => 
                            [woeid] => 0
                        )

                )

            [geoperms] => Array
                (
                    [ispublic] => 1
                    [iscontact] => 0
                    [isfriend] => 0
                    [isfamily] => 0
                )

            [urls] => Array
                (
                    [url] => Array
                        (
                            [0] => Array
                                (
                                    [type] => photopage
                                    [_content] => https://www.flickr.com/photos/cuevalovelle/33289594495/
                                )

                        )

                )

            [media] => photo
        )

    [stat] => ok
)

Datos recibidos

Título: DSC_5107

Subtítulo[0]: Tikal

Autor: cueva_lovelle

Fecha: 2016-08-10 11:45:28

URL: https://www.flickr.com/photos/cuevalovelle/33289594495/

Enlace: 'DSC_5107'

DSC_5107