contentDetails 或持续时间未使用 Youtube v3 api [英] contentDetails or duration not coming using Youtube v3 api
问题描述
看看这个 link ,给了一个例子
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
部分响应是
"contentDetails": {
"duration": "PT15M51S",
"aspectRatio": "RATIO_16_9"
},
现在我想检索 contentDetails 或主要是持续时间.所以我打电话给使用
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
显示
{
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?
推荐答案
如您所见,Search:list 调用不支持 part 参数的 contentDetails.
As you've already found out, the Search:list call does not support contentDetails for the part parameter.
您可以在 Search:list 的参数值中包含的部分名称是 id 和 snippet,它们返回的数据非常少.如果我们想获得关于一个或多个视频的更具体的数据,我们应该使用来自搜索的非常少的数据.
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}
并从响应项中提取 videoId
and extract the videoId from the response items
"id": {
"kind": "youtube#video",
"videoId": "5hzgS9s-tE8"
}
并使用它来进行 Videos:list 调用以获取更具体的数据
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屋!