Requesting News or Event info
support, ws.webtv, api, news, get
GET vars specific to this request:
Var | Value | Description |
go | news | The API section |
do | get | The API action |
iq | News ID | The News or Event 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=news&do=get&iq={news_id}&{required information}
None. No POST vars are required for this request.
If the request was successful, you'll receive a response containing:
• data: The News/Event info.
• categories: The list of Categories associated with the News/Event.
• gallery_images: The News/Event images.
Example:
{ "data": { "allow_comments": "1", "date": "1390561980", "date_formatted": "24\/01\/2014 12:13:00 PM", "date_lastmod": "1414228089", "date_lastmod_formatted": "25\/10\/2014 11:08:09 AM", "description": "This is the news body... ", "description_seo": "This is the news body...", "id": "49", "id_import": null, "id_user": "1", "img_icon": "http:\/\/......\/uploads\/images\/news_49_1405010910_icon.jpg", "img_legend": "", "img_poster": "http:\/\/......\/uploads\/images\/news_49_1405010910_poster.jpg", "img_social": "http:\/\/......\/uploads\/images\/news_49_1405010910_social.jpg", "img_thumbnail": "http:\/\/......\/uploads\/images\/news_49_1405010910_thumb.jpg", "is_featured": "0", "socialize": "1", "status": "1", "tags": "tag1, tag2, tag3", "title": "The News title", "title_url": "the-news-title", "type": "0", "type_name": "news", "url": "http:\/\/......\/index.php\/news\/49\/the-news-title\/", "user_alias": "WebTV", "user_url": "http:\/\/......\/index.php\/portal\/user\/1\/webtv\/", "views_page": "80", "views_page_formatted": "80" }, "categories": [{ "id": 1, "title": "Movies", "breadcrumb": [{ "id": 1, "title": "Movies" }] }], "gallery_images": [{ "date": "1412746497", "date_formatted": "08\/10\/2014 07:34:57 AM", "date_lastmod": "1414228089", "date_lastmod_formatted": "25\/10\/2014 11:08:09 AM", "description": "", "id": "51", "id_gallery": "38", "img_icon": "http:\/\/......\/uploads\/images\/galleries\/gallery_38_image_51_1412746497_icon.jpg", "img_large": "http:\/\/......\/uploads\/images\/galleries\/gallery_38_image_51_1412746497_large.jpg", "img_thumbnail": "http:\/\/......\/uploads\/images\/galleries\/gallery_38_image_51_1412746497_thumb.jpg", "title": "Image 1" }, { "date": "1414227905", "date_formatted": "25\/10\/2014 11:05:05 AM", "date_lastmod": "1414228089", "date_lastmod_formatted": "25\/10\/2014 11:08:09 AM", "description": "", "id": "52", "id_gallery": "38", "img_icon": "http:\/\/......\/uploads\/images\/galleries\/gallery_38_image_52_1414227906_icon.jpg", "img_large": "http:\/\/......\/uploads\/images\/galleries\/gallery_38_image_52_1414227906_large.jpg", "img_thumbnail": "http:\/\/......\/uploads\/images\/galleries\/gallery_38_image_52_1414227906_thumb.jpg", "title": "Image 2" }, { "date": "1414227905", "date_formatted": "25\/10\/2014 11:05:05 AM", "date_lastmod": "1414228089", "date_lastmod_formatted": "25\/10\/2014 11:08:09 AM", "description": "", "id": "53", "id_gallery": "38", "img_icon": "http:\/\/......\/uploads\/images\/galleries\/gallery_38_image_53_1414227906_icon.jpg", "img_large": "http:\/\/......\/uploads\/images\/galleries\/gallery_38_image_53_1414227906_large.jpg", "img_thumbnail": "http:\/\/......\/uploads\/images\/galleries\/gallery_38_image_53_1414227906_thumb.jpg", "title": "Image 3" }] }
If the request failed (for example, if the Credential does not have permission to GET), you'll receive a response like the following:
{ "error" : "REQUEST_ERROR", "error_long" : "Permission error: GET" }
Possible Error Messages
Besides the general errors, this request can return the following errors:
• REQUEST_ERROR | Invalid News/Event ID:
News/Event ID is not numeric or lower than 1.
• REQUEST_ERROR | News/Event not found or inactive
Preparing GET and POST data.
// The GET vars $GET_VARS = array( "go" => "channels", "do" => "get", "iq" => 49 ); // The POST vars $POST_VARS = array();
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)); }