Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
144
rated 0 times [  147] [ 3]  / answers: 1 / hits: 18284  / 10 Years ago, wed, december 10, 2014, 12:00:00

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?


More From » youtube

 Answers
57

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
},

[#68535] Saturday, December 6, 2014, 10 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
beatrices

Total Points: 745
Total Questions: 103
Total Answers: 105

Location: Guam
Member since Tue, Nov 29, 2022
2 Years ago
;