contentDetails或持续时间不会使用Youtube v3 api [英] contentDetails or duration not coming using Youtube v3 api
问题描述
请看这个链接,有一个例子
https://www.googleapis.com/youtube/v3/videos?id=7lCDEYXw3mM&key=YOUR_API_KEY
& amp; part = snippet,contentDetails,统计数据,状态
部分响应是
contentDetails:{
duration:PT15M51S,
aspectRatio:RATIO_16_9
},
现在我想要检索contentDetails或主要持续时间。因此,我使用
https://www.googleapis.com/youtube/v3/search?part=snippet,contentDetails& key = [API_KEY]& q = something& maxResults = 15&& field = item,nextPageToken,prevPageToken,tokenPagination
显示
{
错误:{
错误:[
{
domain:youtube.part,
reason:unknownPart,
message:contentDetails,
locationType:parameter,
location:部分
],
代码:400,
消息:contentDetails
}
}
为什么?我错过了什么?如何检索视频的持续时间?
正如您已经发现的那样,Search:list调用不支持contentDetails为零件参数。
您可以在搜索:列表的参数值中包含的部分名称是id和snippet,而那些返回的数据非常少。如果我们想要获取视频或视频中的更多特定数据,我们应该使用搜索中非常少的数据。
所以,要获得视频持续时间搜索,您必须拨打电话,如 GET https://www.googleapis.com/youtube/ v3 / search?part = id& q = anything& key = {YOUR_API_KEY}
并提取videoId来自回复项目
id:{
kind:youtube#video,
videoId:5hzgS9s-tE8
}
并用它来制作视频:列表调用以获取更具体的数据
https://www.googleapis.com/youtube/v3/videos?id = 5hzgS9s-tE8& key = YOUR_API_KEY& part = snippet,contentDetails,statistics,status
持续时间从响应数据
contentDetails:{
duration:PT15M51S,
aspectRatio:RATIO_16_9
},
Look at this link , there is an example given
https://www.googleapis.com/youtube/v3/videos?id=7lCDEYXw3mM&key=YOUR_API_KEY
&part=snippet,contentDetails,statistics,status
Part of the response is
"contentDetails": {
"duration": "PT15M51S",
"aspectRatio": "RATIO_16_9"
},
Now I want to retrieve contentDetails or mainly duration. So I called using
https://www.googleapis.com/youtube/v3/search?part=snippet,contentDetails&key=[API_KEY]&q=something&maxResults=15&&fields=items,nextPageToken,prevPageToken,tokenPagination
It shows
{
error: {
errors: [
{
domain: "youtube.part",
reason: "unknownPart",
message: "contentDetails",
locationType: "parameter",
location: "part"
}
],
code: 400,
message: "contentDetails"
}
}
Why? What am I missing? How to retrieve the duration for videos?
As you've already found out, the Search:list call does not support contentDetails for the part parameter.
The part names that you can include in the parameter value for Search:list are id and snippet, and those return very little data. We're supposed to use that very little data from a search if we want to get more specific data on a video or videos.
So, to get a video duration when doing a search, you'll have to make a call like
GET https://www.googleapis.com/youtube/v3/search?part=id&q=anything&key={YOUR_API_KEY}
and extract the videoId from the response items
"id": {
"kind": "youtube#video",
"videoId": "5hzgS9s-tE8"
}
and use that to make the Videos:list call to get more specific data
https://www.googleapis.com/youtube/v3/videos?id=5hzgS9s-tE8&key=YOUR_API_KEY&part=snippet,contentDetails,statistics,status
and extract the duration from the response data
"contentDetails": {
"duration": "PT15M51S",
"aspectRatio": "RATIO_16_9"
},
这篇关于contentDetails或持续时间不会使用Youtube v3 api的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!