henry agbasimalo
henry agbasimalo

Reputation: 41

How to add video duration to youtube v3 api native android

am working on youtube player using youtube v3 api. I tried to add video duration using part=ContentDetails to my video search request, but it keeps returning error for contentDetails/duration. Does anybody have any means of getting around this problem. Here is my search request Url code below.

https://www.googleapis.com/youtube/v3/search?contentDetailsorder=viewCount&q=;&type=video&maxResults=14&part=snippet,&fields=items(id/videoId,snippet/title,snippet/thumbnails,contentDetails/duration)&key= Constants.YOUTUBE_API_KEY;

Upvotes: 1

Views: 1068

Answers (1)

theduck
theduck

Reputation: 2617

The Search:List call does not return the duration of a video in its search results. All the fields available can be seen here.

In order to get the duration of the videos call Videos:List with the id field set to a comma delimited list of the videoIds that you get from the search call. For instance:

GET https://www.googleapis.com/youtube/v3/videos?part=contentDetails&id=RgKAFK5djSk%2Cw1oM3kQpXRo&key={YOUR_API_KEY}

you can then access contentDetails\Duration for each of the videos.

Upvotes: 1

Related Questions