Get a viewable embed code for a Clip with access restriction.
support, ws.webtv, api, clips, get_restricted_viewable_embed_code
GET vars specific to this request:
Var | Value | Description |
go | clips | The API section |
do | get_restricted_viewable_embed_code | The API action |
iq | Clip ID | The Clip ID |
Resulting Request URL:
The resulting request URL would be similar to this (don't forget to append the required info: key, timestamp, salt and signature):
https://....../api.php?go=clips&do=get_restricted_viewable_embed_code&iq={url}&{required information}
The following POST var is required.
Var | Value | Description |
id_user | (int) User ID | The ID of the User in the WebTV |
The following POST var are optional (but recommended).
Var | Value | Description |
ip_user | (string) IP Address | The (public) IP of the User who will watch the Clip. If you do not provide it, the system will use the detected IP (the IP of the application which may -or may not- match the IP of the User who will watch the Clip). |
expiration | (int) seconds | Expiration time for the Embed code (in seconds - respect the request time). Once this time has elapsed the Embed code will stop working. |
embedWidth | (int) width | Width for the embed code (in pixels) |
embedHeight | (int) height | Height for the embed code (in pixels) |
embedURLVars | (string) "&var1=value1..." | Video Player URL vars for the Embed code (check the possible URL vars here) |
If the request was successful, you'll receive a response containing:
• embed_code_iframe: Iframe type Embed code.
• embed_code_object: Object type Embed code.
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>" }
If the request failed (for example, if no signature was provided in the request), you'll receive a response like the following:
{ "error" : "REQUEST_ERROR", "error_long" : "Missing signature" }
Possible Error Messages
Besides the general errors, this request can return the following errors:
• REQUEST_ERROR | Invalid Clip ID:
Clip ID is not numeric or lower than 1.
• REQUEST_ERROR | Invalid User ID:
User ID is not numeric or lower than 1.
• REQUEST_ERROR | Invalid expiration time:
Supplied expiration time is not numeric or lower than 1.
Preparing GET and POST data.
// The GET vars $GET_VARS = array( "go" => "clips", "do" => "get_restricted_viewable_embed_code", "iq" => 401 ); // The POST vars $POST_VARS = array( "id_user" => 2, "ip_user" => "xxx.xxx.xxx.xxx", "expiration" => 3600, "embedWidth" => 400, "embedHeight" => 225, "embedURLVars" => "&autoplay=1" );
Generating the salt, timestamp, signature and sending the request
*** The following code block is common to all signed requests ***
// Collect the API Base URL and Credential info $API_URL = "https://www.mywebtvdomain.tv/api.php"; $API_KEY_ID = "1b323a1cb879fd4e66530fbad07a32ee"; $API_SHARED_SECRET = "MWIzMjNhMWNiODc5ZmQ0ZTY2NTMwZmJhZDA3YTMyZWViOTQ3MDJiOGM2ZTU2NjE3"; // keep this safe!!! // Generating salt and timestamp $salt = md5(mt_rand()); $timestamp = time(); $signature = base64_encode(hash_hmac('sha256', $salt.$timestamp, $API_SHARED_SECRET, true)); // Generating the validation signature // - Default method: using base64_encode(hash_hmac(...)) $signature = base64_encode(hash_hmac('sha256', $salt.$timestamp, $API_SHARED_SECRET, true)); // comment this line if using the next method // - Simplified method - available since v60: using md5(). // This method requires the variable $API_SIGNATURE_GENERATION_MODE = 1; in the config/Config.inc.php file. // $signature = md5($salt."-".$timestamp."-".$API_SHARED_SECRET); // you must "uncomment" this line when using the simplified method // Append the timestamp, salt, key and signature to the GET vars $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; // Create the request URL. Please note that if you do not use PHP buit in function // to create the HTTP query then don't forget to URL encode the values $REQUEST_URL = $API_URL."?".http_build_query($GET_VARS); // The previous will build an URL like .../api.php?go=api_subject&do=api_action&etc... // Create a new cURL resource and set the appropriate options $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. // Sending the request to the API $response = curl_exec($ch); // Processing the response if (!$response) { echo 'API call failed'; } else { print_r(json_decode($response,true)); }