gpt4 book ai didi

youtube-api - 如何检查用户是否通过 YouTube API 观看了视频

转载 作者:行者123 更新时间:2023-12-02 03:16:09 25 4
gpt4 key购买 nike

有什么方法可以检查用户是否通过 youtube API 观看了 youtube 上的某些视频?我不仅想知道用户是否点击了视频,还想知道他是否真的看过。我基本上希望您在浏览 youtube 时可以在视频缩略图上看到这些信息。

最佳答案

这里是我的代码,我使用的是 javascript 和 youtube api v3 和 php。希望对你有帮助

`    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;
}`

关于youtube-api - 如何检查用户是否通过 YouTube API 观看了视频,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36956972/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com