如何使用YouTube API获取相关视频的数量?

时间:2021-11-12 18:57:43

I want to get the number of related video and all video list using API V3. For example, If I input the URL of the video, I want get how many related videos of my video at that time and get all related video list(title and URL etc..) Is that possible to do in Javascript?

我想使用API​​ V3获取相关视频和所有视频列表的数量。例如,如果我输入视频的网址,我想获取当时视频的相关视频数量,并获取所有相关视频列表(标题和网址等)。这可以在Javascript中进行吗?

1 个解决方案

#1


0  

You can use simple javascript function to get data from youtube api v3.

您可以使用简单的javascript函数从youtube api v3获取数据。

function Get(yourUrl)
{
var Httpreq = new XMLHttpRequest(); // a new request
Httpreq.open("GET",yourUrl,false);
Httpreq.send(null);
return Httpreq.responseText;         
}

Call the function and use the data in json

调用该函数并使用json中的数据

var json_obj = JSON.parse(Get("yourUrl"));
console.log("this is the author name: "+json_obj.ObjectvalueWhateveritis);

Here your url is

你的网址是

https://www.googleapis.com/youtube/v3/search?key={$this->key}&part={$part}&maxResults={$this->limit}&type=video&relatedToVideoId={$id}

Hope it helps you.

希望它能帮到你。

#1


0  

You can use simple javascript function to get data from youtube api v3.

您可以使用简单的javascript函数从youtube api v3获取数据。

function Get(yourUrl)
{
var Httpreq = new XMLHttpRequest(); // a new request
Httpreq.open("GET",yourUrl,false);
Httpreq.send(null);
return Httpreq.responseText;         
}

Call the function and use the data in json

调用该函数并使用json中的数据

var json_obj = JSON.parse(Get("yourUrl"));
console.log("this is the author name: "+json_obj.ObjectvalueWhateveritis);

Here your url is

你的网址是

https://www.googleapis.com/youtube/v3/search?key={$this->key}&part={$part}&maxResults={$this->limit}&type=video&relatedToVideoId={$id}

Hope it helps you.

希望它能帮到你。