Solicitando la información de una Galería
soporte, ws.webtv, api, galleries, get
Variables GET específicas para esta solicitud:
Var | Valor | Descripción |
go | galleries | La sección del API |
do | get | La acción del API |
iq | ID Galería | ID de la Galería |
URL Resultante:
La URL de solicitud resultante sería similar a la siguiente (no se olvide de añadir la información requerida key, timestamp, salt and signature):
https://....../api.php?go=galleries&do=get&iq={id_galería}&{información requerida}
Ninguna. No se requiren variables POST para esta solicitud.
Si la solicitud es exitosa, recibirá una respuesta conteniendo:
• data: La información de la Galería.
• categories: La lista de Categorías a las que está asociada la Galería.
• gallery_images: Las imágenes de la Galería.
Ejemplo:
{ "data" : { "allow_comments" : "1" , "date" : "1394707840" , "date_formatted" : "13\/03\/2014 11:50:40 AM" , "date_lastmod" : "1426932169" , "date_lastmod_formatted" : "21\/03\/2015 11:02:49 AM" , "description" : "The gallery description" , "description_seo" : "The gallery description" , "id" : "37" , "id_channel" : null , "id_news" : null , "id_user" : "1" , "img_icon" : "http:\/\/......\/uploads\/images\/gallery_37_1382608290_icon.jpg" , "img_poster" : "http:\/\/......\/uploads\/images\/gallery_37_1382608290_poster.jpg" , "img_social" : "http:\/\/......\/uploads\/images\/gallery_37_1382608290_social.jpg" , "img_thumbnail" : "http:\/\/......\/uploads\/images\/gallery_37_1382608290_thumb.jpg" , "is_featured" : "0" , "privacy" : "0" , "privacy_access_level" : "99" , "socialize" : "1" , "status" : "1" , "tags" : "tag1, tag2" , "title" : "My Gallery" , "title_url" : "my-gallery" , "url" : "http:\/\/......\/index.php\/gallery\/37\/my-galley\/" , "user_alias" : "WebTV" , "user_url" : "http:\/\/......\/index.php\/portal\/user\/1\/webtv\/" , "views_page" : "101" , "views_page_formatted" : "101" }, "categories" : [{ "id" : 1, "title" : "Movies" , "breadcrumb" : [{ "id" : 1, "title" : "Movies" }] }, { "id" : 18, "title" : "Animation" , "breadcrumb" : [{ "id" : "1" , "title" : "Movies" }, { "id" : "18" , "title" : "Animation" }] }], "gallery_images" : [{ "date" : "1382608240" , "date_formatted" : "24\/10\/2013 11:50:40 AM" , "date_lastmod" : "1426932169" , "date_lastmod_formatted" : "21\/03\/2015 11:02:49 AM" , "description" : "" , "id" : "34" , "id_gallery" : "37" , "img_icon" : "http:\/\/......\/uploads\/images\/galleries\/gallery_37_image_34_1383812218_icon.jpg" , "img_large" : "http:\/\/......\/uploads\/images\/galleries\/gallery_37_image_34_1383812218_large.jpg" , "img_thumbnail" : "http:\/\/......\/uploads\/images\/galleries\/gallery_37_image_34_1383812218_thumb.jpg" , "title" : "Image 1" }, { "date" : "1382608240" , "date_formatted" : "24\/10\/2013 11:50:40 AM" , "date_lastmod" : "1426932169" , "date_lastmod_formatted" : "21\/03\/2015 11:02:49 AM" , "description" : "" , "id" : "35" , "id_gallery" : "37" , "img_icon" : "http:\/\/......\/uploads\/images\/galleries\/gallery_37_image_35_1385451866_icon.jpg" , "img_large" : "http:\/\/......\/uploads\/images\/galleries\/gallery_37_image_35_1385451866_large.jpg" , "img_thumbnail" : "http:\/\/......\/uploads\/images\/galleries\/gallery_37_image_35_1385451866_thumb.jpg" , "title" : "Image 2" }, { "date" : "1382608240" , "date_formatted" : "24\/10\/2013 11:50:40 AM" , "date_lastmod" : "1426932169" , "date_lastmod_formatted" : "21\/03\/2015 11:02:49 AM" , "description" : "" , "id" : "36" , "id_gallery" : "37" , "img_icon" : "http:\/\/......\/uploads\/images\/galleries\/gallery_37_image_36_1385451867_icon.jpg" , "img_large" : "http:\/\/......\/uploads\/images\/galleries\/gallery_37_image_36_1385451867_large.jpg" , "img_thumbnail" : "http:\/\/......\/uploads\/images\/galleries\/gallery_37_image_36_1385451867_thumb.jpg" , "title" : "Image 3" }] } |
Si la solicitud no es exitosa (por ejemplo, si la Credencial no tiene permiso OBTENER), recibirá una respuesta como la siguiente:
{ "error" : "REQUEST_ERROR" , "error_long" : "Permission error: GET" } |
Posibles Mensajes de Error
Además de los errores generales, esta solicitud puede devolver los siguientes errores:
• REQUEST_ERROR | Invalid Gallery ID:
El ID de la Galería no es numérico o es menor que 1.
• REQUEST_ERROR | Gallery not found, inactive or restricted
No fue posible encontrar una Galería con el ID suministrado.
Preparando los datos GET y POST.
1 2 3 4 5 6 7 8 9 | // Las variables GET $GET_VARS = array ( "go" => "galleries" , "do" => "get" , "iq" => 37 ); // Las variables POST $POST_VARS = array (); |
Generando salt, timestamp, signature y enviando la solicitud
*** El siguiente bloque de código es común para todas las solicitudes firmadas ***
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 | // Recopilando la información del API y URL Base $API_KEY_ID = "1b323a1cb879fd4e66530fbad07a32ee" ; $API_SHARED_SECRET = "MWIzMjNhMWNiODc5ZmQ0ZTY2NTMwZmJhZDA3YTMyZWViOTQ3MDJiOGM2ZTU2NjE3" ; // Mantenga esto en un lugar seguro!!! // Generando salt y timestamp $salt = md5(mt_rand()); $timestamp = time(); // Generando la firma de validación // - Método por defecto: usando base64_encode(hash_hmac(...)) $signature = base64_encode (hash_hmac( 'sha256' , $salt . $timestamp , $API_SHARED_SECRET , true)); // comentar esta línea si se utiliza el otro método // - Método simplificado - disponible desde v60: usando md5(). // Este método requiere que la variable $API_SIGNATURE_GENERATION_MODE = 1; en el archivo config/Config.inc.php.<br> // $signature = md5($salt."-".$timestamp."-".$API_SHARED_SECRET); // debe "des-comentar" esta línea si se utiliza el método simplificado // Añadiendo timestamp, salt, key y signature a las variables GET $GET_VARS [ "timestamp" ] = $timestamp ; // UTC timestamp $GET_VARS [ "salt" ] = $salt ; $GET_VARS [ "key" ] = $API_KEY_ID ; // The API Key ID: This is public and is used by the API to identify the application; $GET_VARS [ "signature" ] = $signature ; // Creando la URL de la solicitud. Tenga presente que si no utiliza la función interna de PHP // para crear la solicitud HTTP entonces no se olvide de codificar los valores con URL Encode $REQUEST_URL = $API_URL . "?" .http_build_query( $GET_VARS ); // Lo anterior construirá una URL del como .../api.php?go=api_subject&do=api_action&etc... // Creando un recurso cURL con las opciones apropiadas $ch = curl_init(); curl_setopt( $ch , CURLOPT_URL, $REQUEST_URL ); curl_setopt( $ch , CURLOPT_POST, true); curl_setopt( $ch , CURLOPT_RETURNTRANSFER, true); curl_setopt( $ch , CURLOPT_HEADER, false); curl_setopt( $ch , CURLOPT_POSTFIELDS, $POST_VARS ); // If your PHP host does not have a valid SSL certificate, you will need to turn off SSL // Certificate Verification. This is dangerous (!), and should only be done temporarily // until a valid certificate has been installed curl_setopt( $ch , CURLOPT_SSL_VERIFYHOST, false); // Turns off verification of the SSL certificate. curl_setopt( $ch , CURLOPT_SSL_VERIFYPEER, false); // Turns off verification of the SSL certificate. // Enviando la solicitud al API $response = curl_exec( $ch ); // Procesando la respuesta if (! $response ) { echo 'Llamada al API falló' ; } else { print_r(json_decode( $response ,true)); } |