Youtube api 如何检查用户是否通过YouTube API观看了视频
有没有办法检查用户是否通过youtube API观看了youtube上的视频?我不仅想知道用户是否点击了视频,还想知道他是否真的观看了视频。我基本上希望在浏览youtube时可以在视频缩略图上看到显示已观看的信息。这里是我的代码,我使用的是javascript和youtube api v3和php。希望对你有帮助Youtube api 如何检查用户是否通过YouTube API观看了视频,youtube-api,youtube-data-api,youtube-javascript-api,Youtube Api,Youtube Data Api,Youtube Javascript Api,有没有办法检查用户是否通过youtube API观看了youtube上的视频?我不仅想知道用户是否点击了视频,还想知道他是否真的观看了视频。我基本上希望在浏览youtube时可以在视频缩略图上看到显示已观看的信息。这里是我的代码,我使用的是javascript和youtube api v3和php。希望对你有帮助 ` protected function getHistory($vid){ $return = new stdClass(); $videos = $v
` protected function getHistory($vid){
$return = new stdClass();
$videos = $vid;
$vids[] =$vid;
$videos = explode("\n", $videos);
$videos = implode(",", array_map("rtrim", $videos));
$part = "snippet,contentDetails,statistics";
$this->url = "https://www.googleapis.com/youtube/v3/videos?key= {$this->key}&part={$part}&id={$videos}";
$data = $this->http(TRUE);
$html ="<h2 class='header'>Your Recently Viewed Videos</h2> <a href='#' class='header' onclick='clearhistory();'>Clear History</a>";
$html .= "<ul class='media' id='mediacontent'>";
$vids = array();
foreach ($data->items as $yt) {
$html .= $this->listhisVideo($yt);
$vids[] = $yt->id;
}
$html .= "</ul>";
$html .=$this->ads(728);
$html .= '<script type="text/javascript">
var videos = ["'.implode('","',$vids).'"];
</script>';
if(!isset($_POST['his'])) {
$html ="<h2 class='header'>Your Recently Viewed Videos</h2>";
$html .='<ul class="media"><li class="video" id="video-EoCz3Vx1pXg">
<center><img src="/img/load.gif"></center>
</li></ul>';
$html .= '<form id="history" action="/history" method="POST">
<input type="hidden" id= "his" name="his" value="NqucyQdiFRM,EoCz3Vx1pXg,FJ55SHCzt88" />
</form><script type="text/javascript">
if (localStorage.getItem("videos") === null) {
document.getElementById("his").value = "empty";
} else {
document.getElementById("his").value = localStorage.getItem("videos");
}
document.getElementById("history").submit();
</script>';
}
if ($_POST['his']=='empty'){
$html ="<h2 class='header'>Your Recently Viewed Videos</h2>";
$html .="NO Video Exist";
}
$return->html = $html;
return $return;
}`
受保护的函数getHistory($vid){
$return=新stdClass();
$videos=$vid;
$vids[]=$vid;
$videos=爆炸(“\n”,$videos);
$videos=内爆(“,”,数组映射(“rtrim”,$videos));
$part=“snippet,contentDetails,statistics”;
$this->url=”https://www.googleapis.com/youtube/v3/videos?key= {$this->key}&part={$part}&id={$videos}”;
$data=$this->http(TRUE);
$html=“您最近观看的视频”;
$html.=“- ”;
$vids=array();
foreach($data->项目为$yt){
$html.=$this->listhisVideo($yt);
$vids[]=$yt->id;
}
$html.=“
Post your attemepti在youtube api文档中未找到任何api端点,该端点将返回此类信息用户是否需要使用Oauth进行身份验证?这一点很重要。用户通过OAuth进行身份验证。您能解释一下这段代码吗?我可以看到您正在请求/youtue/v3/视频,但这并不能告诉您用户是否观看了该视频。同意@Dejvid(并被否决):这列出了通过
$vid
传递的视频的详细信息,但没有说明用户最近观看了什么。通过当前API,“最近观看”似乎不可能。