Get the list of Users who viewed a content, until the present time.
support, ws.webtv, api, users, list_who_viewed_content
GET vars specific to this request:
Var | Value | Description |
go | users | The API section |
do | list_who_viewed_content | The API action |
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=users&do=list_who_viewed_content&{required information}
The following POST vars are required.
Var | Value | Description |
contentType | (string) Content Type | Possibles values: "clip", "channel" (valid for video channels and pages), "gallery", "news" (valid for news and events). |
contentID | (int) Content ID | ID of the Clip, Channel/Page, News/Event or Gallery. |
The following POST vars are optional.
Var | Value | Description |
includeUserData | (int) 0|1 | Whether you want to retrieve basic User data (login, alias, name, surname) along the results. |
getHeatmapURL | (int) 0/1 | [Only if contentType="clip"] Whether to include the URL of the heatmap image. NOTE: This variable is available since WS.WebTV 2.2.0.3. |
likeFavoriteFilter | (string) option | [Only if contentType="clip"] To restrict the list to those users who have liked and/or favorited the content. Possible values: "liked", "favorited", "likedAndFavorited" NOTE: This variable is available since WS.WebTV 3.1 (R50) |
If the request was successful, you'll receive a response containing:
• list: An array with the list of Users who viewed the content until present time (with stats).
Example [List of Users who viewed a particular Clip]:
{ "list": [ { "id_user": "22", "login": "mark", "alias": "Markus", "name": "Mark", "surname": "Johnson", "total_playbacks": "27", "complete_playbacks": "4", "last_played_second": "15", "duration": "15", "total_play_time": "98", "page_views": "11" }, { "id_user": "39", "login": "david99", "alias": "DavidOn", "name": "David", "surname": "McDonald", "total_playbacks": "19", "complete_playbacks": "2", "last_played_second": "10", "duration": "15", "total_play_time": "50", "page_views": "0" }, (...) ] }
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 Content ID:
Content ID is not numeric or lower than 1.
• REQUEST_ERROR | Invalid Content Type [Must be 'clip', 'channel', 'news' or 'gallery']:
Unexpected value for contentType.
Preparing GET and POST data.
// The GET vars $GET_VARS = array( "go" => "users", "do" => "list_who_viewed_content" ); // The POST vars $POST_VARS = array( "contentType" => "clip", "contentID" => 2, "includeUserData" => 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 the salt, timestamp and validation signature $salt = md5(mt_rand()); $timestamp = time(); $signature = base64_encode(hash_hmac('sha256', $salt.$timestamp, $API_SHARED_SECRET, true)); // 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)); }