ssougnez
ssougnez

Reputation: 5886

Search for YouTube videos duration, channel, and view count

I'd like to use the YouTube search API (v3) in order to search videos based on a keyword. It works well and here is an example of what I receive:

{
   "kind": "youtube#searchResult",
   "etag": "\"dhbhlDw5j8dK10GxeV_UG6RSReM/hJdddtiTPMTxfi76U5-OfoXwfPE\"",
   "id": {
    "kind": "youtube#video",
    "videoId": "TE9TpraPlrE"
   },
   "snippet": {
    "publishedAt": "2010-06-29T17:00:38.000Z",
    "channelId": "UCikzJG7RbnNZhKLqqaXRM6A",
    "title": "What is SharePoint? | lynda.com overview",
    "description": "This web development overview explores what SharePoint is and how it works. Watch more at ...",
    "thumbnails": {
     "default": {
      "url": "https://i.ytimg.com/vi/TE9TpraPlrE/default.jpg"
     },
     "medium": {
      "url": "https://i.ytimg.com/vi/TE9TpraPlrE/mqdefault.jpg"
     },
     "high": {
      "url": "https://i.ytimg.com/vi/TE9TpraPlrE/hqdefault.jpg"
     }
    },
    "channelTitle": "lyndapodcast",
    "liveBroadcastContent": "none"
   }
  }

However, I miss some information like the duration, the real name of the channel, and the number of views. I guess there is another API entry point to get this information about one or several videos but is it possible to get ALL this information in one call? Meaning that the search API would return them as well or am I forced to sum up all the video the search returned and make a second call to get information for all these videos?

Upvotes: 1

Views: 2194

Answers (1)

Daniel Storm
Daniel Storm

Reputation: 18908

Duration, channel, and views are not returned by search. You will need to pass the videoId's to video to get the information you require. For example, using videoId Pxb5lSPLy9c and setting part to show statistics and contentDetails will result in the return of the duration and view count.

Request:

GET https://www.googleapis.com/youtube/v3/videos?part=statistics%2C+contentDetails&id=Pxb5lSPLy9c&key={YOUR_API_KEY}

Response:

{
 "kind": "youtube#videoListResponse",
 "etag": "\"dhbhlDw5j8dK10GxeV_UG6RSReM/2DniKZoxyNGn7I9fMnpuXArVy7I\"",
 "pageInfo": {
  "totalResults": 1,
  "resultsPerPage": 1
 },
 "items": [
  {
   "kind": "youtube#video",
   "etag": "\"dhbhlDw5j8dK10GxeV_UG6RSReM/866ffq8I1qvVuqduMHhbik3U_Ow\"",
   "id": "Pxb5lSPLy9c",
   "contentDetails": {
    "duration": "PT9M18S",
    "dimension": "2d",
    "definition": "hd",
    "caption": "true",
    "licensedContent": true
   },
   "statistics": {
    "viewCount": "3112372",
    "likeCount": "125358",
    "dislikeCount": "973",
    "favoriteCount": "0",
    "commentCount": "10242"
   }
  }
 ]
}

Upvotes: 2

Related Questions