18

I am using youtube data api version 3, to get the top youtube videos, i am calling the REST api like this:

https://developers.google.com/apis-explorer/#p/youtube/v3/youtube.search.list?part=snippet&forMine=true&maxResults=10&order=viewCount&type=video&_h=6&

and get the data like this is json format:

"kind": "youtube#searchResult",
"etag": "adasdasdasdasdas",
"id": 
{
  "kind": "youtube#video",
  "videoId": "123123asdsad12"
},
"snippet": 
{
  "publishedAt": "date",
  "channelId": "Gasdqqweqweqwr123123",
  "title": "my tutle",
  "description": "xyz",
  "thumbnails": 
  {
    "default": 
    {
      "url": "......jpg",
      "width": 120,
      "height": 90
    },
    "medium": 
    {
      "url": "......jpg",
      "width": 320,
      "height": 180
    },
    "high": 
    {
      "url": "......jpg",
      "width": 480,
      "height": 360
    }
  },
  "liveBroadcastContent": "none"
}

but this data do not contain youtube video url, how can i obtain it from the api?

Ondrej Svejdar
  • 21,349
  • 5
  • 54
  • 89
Sanjay Bathre
  • 451
  • 1
  • 5
  • 17

2 Answers2

61

You can have the video url like this :

You have the result :

     "kind": "youtube#searchResult",
"etag": "\"adasdasdasdasdas"",
"id": {
"kind": "youtube#video",
"videoId": "123123asdsad12"
},
...

Now you get the field "videoId": "123123asdsad12"

And you can acces to the video via the link:

https://www.youtube.com/watch?v=123123asdsad12

And that's it !

mpgn
  • 7,121
  • 9
  • 67
  • 100
  • Is there a way to get full link programmatically? we have the id that is OK, but what if the link format changes for example "id" instead of "v". Like "https://www.youtube.com/watch?id=123123asdsad12" – sulu.dev May 20 '15 at 09:34
  • it's `v` ad it never change :) – mpgn May 20 '15 at 10:11
  • 2
    Why is that the correct answer? That youtube link sends to the HTML youtube page. It would be better using the youtube embed link https://www.youtube.com/embed/{The id} – user3502626 Aug 28 '16 at 05:09
1

on your query, the "part" property actually indicates what information you want for the call to return, the "snippet" valie will return a more detailed information for each result, if you want the "videoID" data do the following, on the "part" property add "id" value, like this: ...?part=snippet,id&...

that will get you the data that contains the videoID information.

regards.

Mix
  • 11
  • 1