Obtenga un código embed reproducible para un Clip con restricción de acceso.
soporte, ws.webtv, api, clips, get_restricted_viewable_embed_code
Variables GET específicas para esta solicitud:
Var | Valor | Descripción |
go | clips | La sección del API |
do | get_restricted_viewable_embed_code | La acción del API |
iq | ID Clip | El ID del Clip |
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=clips&do=get_restricted_viewable_embed_code&iq={url}&{información requerida}
La siguiente variable POST es requerida.
Var | Valor | Descripción |
id_user | (int) ID Usuario | La ID del usuario en la WebTV |
La siguientes variables POST son opcionales (pero recomendadas).
Var | Valor | Descripción |
ip_user | (string) Dirección IP | La IP (pública) del Usuario que reproducirá el Clip. Si no la suministra, el sistema utilizará la IP detectada (la IP de la aplicación la cual puede -o puede que no- coincida con la IP del Usuario que reproducirá el Clip). |
expiration | (int) seconds | Tiempo de expiración para el código Embed (en segundos - respecto al momento de la solicitud). Una vez transcurrido este tiempo el código Embed dejará de funcionar. |
embedWidth | (int) width | Ancho del código Embed (en pixels) |
embedHeight | (int) height | Alto del código Embed (en pixels) |
embedURLVars | (string) "&var1=value1..." | Variables URL del reproductor de vídeo para el código Embed (consulte las posibles variables aquí) |
Si la solicitud es exitosa, recibirá una respuesta conteniendo:
• embed_code_iframe: Código Embed tipo Iframe.
• embed_code_object: Código Embed tipo Object.
Example:
{ "embed_code_iframe": "<iframe src=\"http:\/\/......\/embed.php?id=401&w=400&h=300&autoplay=1&permission=eyJ0aW1lc3RhbXAiOjE0Mjc1NDAzMTAsImV4cGlyYXRpb24iOjM2MDAsImlkX3VzZXIiOjIsImlwX3VzZXIiOiI2Mi4xMTcuMjE2LjExIiwia2V5IjoiMWIzMjNhMWNiODc5ZmQ0ZTY2NTMwZmJhZDA3YTMyZWUifQ%3D%3D&signature=23EXYoB3mqUDkCm6rYo%2BxY309UOuEvjM2kVr4fn4%2FNI%3D\" scrolling=\"no\" frameborder=\"0\" style=\"border:none; overflow:hidden; width:400px; height:300px;\" webkitAllowFullScreen mozallowfullscreen allowFullScreen><\/iframe>", "embed_code_object": "<div id=\"videoContainer401\"><object classid=\"clsid:D27CDB6E-AE6D-11CF-96B8-444553540000\" id=\"embeddedVideo\" width=\"400\" height=\"300\" codebase=\"http:\/\/download.macromedia.com\/pub\/shockwave\/cabs\/flash\/swflash.cab#version=10,1,0,0\" style=\"border:none\" ><param name=\"movie\" value=\"http:\/\/......\/public\/common\/player.swf?type=clip&id=401&viddiv=videoContainer401&autoplay=1&permission=eyJ0aW1lc3RhbXAiOjE0Mjc1NDAzMTAsImV4cGlyYXRpb24iOjM2MDAsImlkX3VzZXIiOjIsImlwX3VzZXIiOiI2Mi4xMTcuMjE2LjExIiwia2V5IjoiMWIzMjNhMWNiODc5ZmQ0ZTY2NTMwZmJhZDA3YTMyZWUifQ%3D%3D&signature=23EXYoB3mqUDkCm6rYo%2BxY309UOuEvjM2kVr4fn4%2FNI%3D\"><\/param><param name=\"allowFullScreen\" value=\"true\"><\/param><param name=\"allowscriptaccess\" value=\"always\"><\/param><param name=\"SCALE\" value=\"ExactFit\"><\/param><param name=\"quality\" value=\"High\"><\/param><param name=\"loop\" value=\"false\"><\/param><param name=\"swliveconnect\" value=\"true\"><\/param><param name=\"wmode\" value=\"opaque\"><\/param><embed name=\"embeddedVideo\" width=\"400\" height=\"300\" src=\"http:\/\/......\/public\/common\/player.swf?type=clip&id=401&viddiv=videoContainer401&autoplay=1&permission=eyJ0aW1lc3RhbXAiOjE0Mjc1NDAzMTAsImV4cGlyYXRpb24iOjM2MDAsImlkX3VzZXIiOjIsImlwX3VzZXIiOiI2Mi4xMTcuMjE2LjExIiwia2V5IjoiMWIzMjNhMWNiODc5ZmQ0ZTY2NTMwZmJhZDA3YTMyZWUifQ%3D%3D&signature=23EXYoB3mqUDkCm6rYo%2BxY309UOuEvjM2kVr4fn4%2FNI%3D\" type=\"application\/x-shockwave-flash\" pluginspage=\"http:\/\/www.macromedia.com\/go\/getflashplayer\" allowscriptaccess=\"always\" quality=\"High\" loop=\"false\" allowfullscreen=\"true\" scale=\"exactFit\" swliveconnect=\"true\"><\/embed><\/object><\/div>" }
Si la solicitud no es exitosa (por ejemplo, si no suministró una firma con la solicitud), recibirá una respuesta como la siguiente:
{ "error" : "REQUEST_ERROR", "error_long" : "Missing signature" }
Posibles Mensajes de Error
Además de los errores generales, esta solicitud puede devolver los siguientes errores:
• REQUEST_ERROR | Invalid Clip ID:
El ID del Clip no es numérico o es menor que 1.
• REQUEST_ERROR | Invalid User ID:
El ID del Usuario no es numérico o es menor que 1.
• REQUEST_ERROR | Invalid expiration time:
El tiempo de expiración suministrado no es numérico o es menor que 1.
Preparando los datos GET y POST.
// Las variables GET $GET_VARS = array( "go" => "clips", "do" => "get_restricted_viewable_embed_code", "iq" => 401 ); // Las variables POST $POST_VARS = array( "id_user" => 2, "ip_user" => "xxx.xxx.xxx.xxx", "expiration" => 3600, "embedWidth" => 400, "embedHeight" => 225, "embedURLVars" => "&autoplay=1" );
Generando salt, timestamp, signature y enviando la solicitud
*** El siguiente bloque de código es común para todas las solicitudes firmadas ***
// Recopilando la información del API y URL Base $API_URL = "https://www.midominiowebtv.tv/api.php"; $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.
// $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)); }