How to identify to liveevent and livestream association? - youtube-api

I had created an live event on youtube and i had associated a custom ingestion (live stream) to that live event.
I am able to get the list of live events by calling
https://www.googleapis.com/youtube/v3/liveBroadcasts?part=snippet&broadcastStatus=all
Response
{
"kind": "youtube#liveBroadcastListResponse",
"etag": "\"sGDdEsjSJ_SnACpEvVQ6MtTzkrI/6LS8J5LIkMcXRAIUEViaRonO_jk\"",
"items": [
{
"kind": "youtube#liveBroadcast",
"etag": "\"sGDdEsjSJ_SnACpEvVQ6MtTzkrI/eSW3gnAC5A4iNg4xj-r8vvP4ha8\"",
"id": "M96Pswa174I",
"snippet": {
"publishedAt": "2015-08-27T09:26:52.000Z",
"channelId": "UCx_ZkmygOl4Bc0PHV8zXeag",
"title": "My new event",
"description": "This is test event",
"thumbnails": {
"default": {
"url": "https://i.ytimg.com/vi/M96Pswa174I/default_live.jpg",
"width": 120,
"height": 90
},
"medium": {
"url": "https://i.ytimg.com/vi/M96Pswa174I/mqdefault_live.jpg",
"width": 320,
"height": 180
},
"high": {
"url": "https://i.ytimg.com/vi/M96Pswa174I/hqdefault_live.jpg",
"width": 480,
"height": 360
}
},
"scheduledStartTime": "2015-08-27T09:30:00.000Z",
"isDefaultBroadcast": false
}
}
]
}
then i am able to get the live stream by calling
https://www.googleapis.com/youtube/v3/liveStreams?part=cdn%2Csnippet&mine=true
Response
- SHOW HEADERS -
{
"kind": "youtube#liveStreamListResponse",
"etag": "\"sGDdEsjSJ_SnACpEvVQ6MtTzkrI/ctbzD5B9MI-wBMxDXCWCto2oFO8\"",
"pageInfo": {
"totalResults": 1,
"resultsPerPage": 5
},
"items": [
{
"kind": "youtube#liveStream",
"etag": "\"sGDdEsjSJ_SnACpEvVQ6MtTzkrI/LEFmnjMqvHydtqmxovlaXCai3vM\"",
"id": "x_ZkmygOl4Bc0PHV8zXeag1440668944469033",
"snippet": {
"publishedAt": "2015-08-27T09:49:04.000Z",
"channelId": "UCx_ZkmygOl4Bc0PHV8zXeag",
"title": "My new stream",
"description": "this is demo stream",
"isDefaultStream": false
},
"cdn": {
"format": "720p_hfr",
"ingestionType": "rtmp",
"ingestionInfo": {
"streamName": "rathodm63.6584-jszu-8p4h-43yg",
"ingestionAddress": "rtmp://a.rtmp.youtube.com/live2",
"backupIngestionAddress": "rtmp://b.rtmp.youtube.com/live2?backup=1"
}
}
}
]
}
but how to identify that this steam belongs to above specified live event ?

You must use LiveBroadcasts.bind to bind a YouTube broadcast to a stream. Note that a broadcast can only be bound to one video stream, although a video stream may be bound to more than one broadcast. Then, you can use the LiveBroadcasts.list request and check the contentDetails.boundStreamId, which will be the stream associated with that livebroadcast. You'll have to specify part=contentDetails if you want to do this through an HTTP request.

Related

Youtube API Playlists not returning the Playlist

I am using the Playlists endpoint of Youtube's API to get the playlists from a specific channel but it doesn't work for the following channels:
https://www.youtube.com/channel/UCX5fyLRcU05DMa2OVu-qFEQ
https://www.youtube.com/channel/UCwm2mdiUXApmL5bCxHtgJIA
The query I am using:
https://www.googleapis.com/youtube/v3/playlists?channelId=UCwm2mdiUXApmL5bCxHtgJIA&part=snippet&order=date&maxResults=50&key=YOUR_API_KEY
https://www.googleapis.com/youtube/v3/playlists?channelId=UCX5fyLRcU05DMa2OVu-qFEQ&part=snippet&order=date&maxResults=50&key=YOUR_API_KEY
It doesn't return the videos when I try to target the playlists in these channels using the specif Playlist ID as well. I can see that these channels, playlists and videos are public and searchable.
Is there any reason why the API shouldn't return this playlist that I am missing?
Thank you for your help.
Bartu
If you check the playlist page of the channel you provided, you'll see that all playlists posted there are not really from the channel - those were added/generated by YouTube itself.
Example:
https://www.youtube.com/playlist?list=OLAK5uy_nvZSUlZB8qwifPgIVCoEulF4VyErdBX48
A normal playlist (that belongs to the channel) should have its ID as follows:
PL3tRBEVW0hiB5KKP9gs_AkW8J4dOvbdPN
By using YouTube Data API, you can test the results:
URL: https://youtube.googleapis.com/youtube/v3/playlists?part=id%2Csnippet%2Cstatus&id=OLAK5uy_nvZSUlZB8qwifPgIVCoEulF4VyErdBX48&key=[YOUR_API_KEY]
Results:
{
"kind": "youtube#channelListResponse",
"etag": "Yw1yJOOwI7LJ8LeYmvQ8wpyHWbU",
"pageInfo": {
"totalResults": 1,
"resultsPerPage": 5
},
"items": [
{
"kind": "youtube#channel",
"etag": "wDhMSGEntArTZuX56hjNjytDUlU",
"id": "UCFtEEv80fQVKkD4h1PF-Xqw",
"snippet": {
"title": "Microsoft",
"description": "Innovation is a key ingredient in Microsoft’s mission: to empower every person and organization on the planet to achieve more. \n\nSubscribe to Microsoft's official YouTube channel to explore technology’s role in making the world more sustainable, inclusive, and innovative for all.\n\n",
"customUrl": "microsoft",
"publishedAt": "2006-02-13T05:21:44Z",
"thumbnails": {
"default": {
"url": "https://yt3.ggpht.com/ytc/AKedOLRZENZBPyEEG2cd0PZXemKKyG1GMGVJXmzHhrs4=s88-c-k-c0x00ffffff-no-rj",
"width": 88,
"height": 88
},
"medium": {
"url": "https://yt3.ggpht.com/ytc/AKedOLRZENZBPyEEG2cd0PZXemKKyG1GMGVJXmzHhrs4=s240-c-k-c0x00ffffff-no-rj",
"width": 240,
"height": 240
},
"high": {
"url": "https://yt3.ggpht.com/ytc/AKedOLRZENZBPyEEG2cd0PZXemKKyG1GMGVJXmzHhrs4=s800-c-k-c0x00ffffff-no-rj",
"width": 800,
"height": 800
}
},
"localized": {
"title": "Microsoft",
"description": "Innovation is a key ingredient in Microsoft’s mission: to empower every person and organization on the planet to achieve more. \n\nSubscribe to Microsoft's official YouTube channel to explore technology’s role in making the world more sustainable, inclusive, and innovative for all.\n\n"
},
"country": "US"
},
"contentDetails": {
"relatedPlaylists": {
"likes": "",
"uploads": "UUFtEEv80fQVKkD4h1PF-Xqw"
}
},
"status": {
"privacyStatus": "public",
"isLinked": true,
"longUploadsStatus": "longUploadsUnspecified"
}
}
]
}
When you query a normal playlist (that belongs to the channel), you will get these results:
URL: https://youtube.googleapis.com/youtube/v3/playlists?part=id%2Csnippet%2Cstatus&id=PL3tRBEVW0hiB5KKP9gs_AkW8J4dOvbdPN&key=[YOUR_API_KEY]
Results:
{
"kind": "youtube#playlistListResponse",
"etag": "OV6gnfMDH09mU3YBdHPuf5uz1Jg",
"pageInfo": {
"totalResults": 1,
"resultsPerPage": 5
},
"items": [
{
"kind": "youtube#playlist",
"etag": "X8YVDKLXZZfHlVTh_ud0LD-IMMQ",
"id": "PL3tRBEVW0hiB5KKP9gs_AkW8J4dOvbdPN",
"snippet": {
"publishedAt": "2016-05-15T15:29:30Z",
"channelId": "UC7_YxT-KID8kRbqZo7MyscQ",
"title": "DOOM",
"description": "",
"thumbnails": {
"default": {
"url": "https://i.ytimg.com/vi/pCygvprsgIk/default.jpg",
"width": 120,
"height": 90
},
"medium": {
"url": "https://i.ytimg.com/vi/pCygvprsgIk/mqdefault.jpg",
"width": 320,
"height": 180
},
"high": {
"url": "https://i.ytimg.com/vi/pCygvprsgIk/hqdefault.jpg",
"width": 480,
"height": 360
},
"standard": {
"url": "https://i.ytimg.com/vi/pCygvprsgIk/sddefault.jpg",
"width": 640,
"height": 480
},
"maxres": {
"url": "https://i.ytimg.com/vi/pCygvprsgIk/maxresdefault.jpg",
"width": 1280,
"height": 720
}
},
"channelTitle": "Markiplier",
"localized": {
"title": "DOOM",
"description": ""
}
},
"status": {
"privacyStatus": "public"
}
}
]
}
Check this answer for more details.

Retrieve Video IDs contained in a Playlist - YouTube API v3

I've been using the following method to retrieve all video IDs, titles, and default thumbnail images contained within a specific YouTube playlist for use in a dynamic playlist carousel (The IDs are then passed to an array which is used to dynamically create a thumbnail carousel. Note the 'playlist' variable is defined via an externalized XML value):
// Get YouTube Playlist values
var playListURL = 'http://gdata.youtube.com/feeds/api/playlists/' + playlist + '?v=2&alt=json&callback=?';
var videoURL = 'http://www.youtube.com/watch?v=';
$.getJSON(playListURL, function(data) {
var list_data = "";
$.each(data.feed.entry, function(i, item) {
var feedTitle = item.title.$t;
var feedURL = item.link[1].href;
var fragments = feedURL.split("/");
var videoID = fragments[fragments.length - 2];
var thumb = ""+ videoID +"/sddefault.jpg";
if (videoID !='videos') {
yt_videos.push(videoID);
}
yt_thumb.push(thumb);
yt_title.push(feedTitle);
});
$(list_data).appendTo(".cont");
populateCarousel();
});
YouTube has depricated the v1-2 APIs and the method is longer working. Does the YouTube API v3 provide an equivalent method? Specifically replacing the call:
var playListURL = 'http://gdata.youtube.com/feeds/api/playlists/' + playlist + '?v=2&alt=json&callback=?';
You will need to switch to the new PlaylistItems/list endpoint to get video information from a playlist.
Request:
HTTP GET: GET https://www.googleapis.com/youtube/v3/playlistItems?part=snippet%2C+id&playlistId=PLCJLiJ8uSJrCpxwz4lmnz1NvvF2SzXbhk&key={YOUR_API_KEY}
Response (for id= PLCJLiJ8uSJrCpxwz4lmnz1NvvF2SzXbhk):
{
"kind": "youtube#playlistItemListResponse",
"etag": "\"dhbhlDw5j8dK10GxeV_UG6RSReM/pBQT3k1NWD9D6HOvzNhT4QS1-W0\"",
"nextPageToken": "CAUQAA",
"pageInfo": {
"totalResults": 10,
"resultsPerPage": 5
},
"items": [
{
"kind": "youtube#playlistItem",
"etag": "\"dhbhlDw5j8dK10GxeV_UG6RSReM/wu_RMwA6QYinWSMrYXyOugKDbyI\"",
"id": "PLl3eZeHB033DOxfNMOVENodvC_4QtQ-r2bxEjeNprDxQ",
"snippet": {
"publishedAt": "2014-12-10T21:16:39.000Z",
"channelId": "UCVUx0VcNxnHx7ZjuZK5Sthw",
"title": "Private video",
"description": "This video is private.",
"channelTitle": "Late Show with David Letterman",
"playlistId": "PLCJLiJ8uSJrCpxwz4lmnz1NvvF2SzXbhk",
"position": 0,
"resourceId": {
"kind": "youtube#video",
"videoId": "4bVgilYncao"
}
}
},
{
"kind": "youtube#playlistItem",
"etag": "\"dhbhlDw5j8dK10GxeV_UG6RSReM/DPNyicQckvtlwgMTintYEwYsE6g\"",
"id": "PLl3eZeHB033DOxfNMOVENoaZ-Ybk0W0zkTL1Sliq5xeA",
"snippet": {
"publishedAt": "2014-12-10T21:16:58.000Z",
"channelId": "UCVUx0VcNxnHx7ZjuZK5Sthw",
"title": "David Letterman Announces His Retirement from the Late Show",
"description": "David Letterman announces that he will retire from the Late Show in 2015.\n\nLive on Letterman is up for a Webby award! Let your voice be heard and vote now! http://bit.ly/1l4oktE #WebbyAwards",
"thumbnails": {
"default": {
"url": "https://i.ytimg.com/vi/H9eYkpgeeI8/default.jpg",
"width": 120,
"height": 90
},
"medium": {
"url": "https://i.ytimg.com/vi/H9eYkpgeeI8/mqdefault.jpg",
"width": 320,
"height": 180
},
"high": {
"url": "https://i.ytimg.com/vi/H9eYkpgeeI8/hqdefault.jpg",
"width": 480,
"height": 360
},
"standard": {
"url": "https://i.ytimg.com/vi/H9eYkpgeeI8/sddefault.jpg",
"width": 640,
"height": 480
},
"maxres": {
"url": "https://i.ytimg.com/vi/H9eYkpgeeI8/maxresdefault.jpg",
"width": 1280,
"height": 720
}
},
"channelTitle": "Late Show with David Letterman",
"playlistId": "PLCJLiJ8uSJrCpxwz4lmnz1NvvF2SzXbhk",
"position": 1,
"resourceId": {
"kind": "youtube#video",
"videoId": "H9eYkpgeeI8"
}
}
},
{
"kind": "youtube#playlistItem",
"etag": "\"dhbhlDw5j8dK10GxeV_UG6RSReM/aL6XWPV0PoM50wQcyclAxsvtWy4\"",
"id": "PLl3eZeHB033DOxfNMOVENobu4IxNcwxZw1eEEoLqHjhY",
"snippet": {
"publishedAt": "2014-12-10T21:17:14.000Z",
"channelId": "UCVUx0VcNxnHx7ZjuZK5Sthw",
"title": "Private video",
"description": "This video is private.",
"channelTitle": "Late Show with David Letterman",
"playlistId": "PLCJLiJ8uSJrCpxwz4lmnz1NvvF2SzXbhk",
"position": 2,
"resourceId": {
"kind": "youtube#video",
"videoId": "ONgN2Hgz3XE"
}
}
},
{
"kind": "youtube#playlistItem",
"etag": "\"dhbhlDw5j8dK10GxeV_UG6RSReM/YF1JYH8bTG20vjuPLeMR-2xkxjo\"",
"id": "PLl3eZeHB033DOxfNMOVENoQncF7sXo86YALoy5U4yqlU",
"snippet": {
"publishedAt": "2014-12-10T21:17:30.000Z",
"channelId": "UCVUx0VcNxnHx7ZjuZK5Sthw",
"title": "David Letterman - Future Islands: \"Seasons (Waiting On You)\"",
"description": "Making their network TV debut, Future Islands performed \"Seasons (Waiting On You)\" from their album, \"Singles.\"",
"thumbnails": {
"default": {
"url": "https://i.ytimg.com/vi/1Ee4bfu_t3c/default.jpg",
"width": 120,
"height": 90
},
"medium": {
"url": "https://i.ytimg.com/vi/1Ee4bfu_t3c/mqdefault.jpg",
"width": 320,
"height": 180
},
"high": {
"url": "https://i.ytimg.com/vi/1Ee4bfu_t3c/hqdefault.jpg",
"width": 480,
"height": 360
}
},
"channelTitle": "Late Show with David Letterman",
"playlistId": "PLCJLiJ8uSJrCpxwz4lmnz1NvvF2SzXbhk",
"position": 3,
"resourceId": {
"kind": "youtube#video",
"videoId": "1Ee4bfu_t3c"
}
}
},
{
"kind": "youtube#playlistItem",
"etag": "\"dhbhlDw5j8dK10GxeV_UG6RSReM/_Ft_7ujRwQbP7-altelmVnzwQx0\"",
"id": "PLl3eZeHB033DOxfNMOVENoYQ9Z55P4r2KhvkV5yx-okc",
"snippet": {
"publishedAt": "2014-12-10T21:17:47.000Z",
"channelId": "UCVUx0VcNxnHx7ZjuZK5Sthw",
"title": "Private video",
"description": "This video is private.",
"channelTitle": "Late Show with David Letterman",
"playlistId": "PLCJLiJ8uSJrCpxwz4lmnz1NvvF2SzXbhk",
"position": 4,
"resourceId": {
"kind": "youtube#video",
"videoId": "Bzr5VtFvSyw"
}
}
}
]
}
The id value for each object in the items array should be the videoId value that you want.
api_key = 'YOUR_API_KEY'
api_service_name = 'youtube'
api_version = 'v3'
playlist_id = 'SOME_PLAYLIST_ID'
# build a connected client
youtube = googleapiclient.discovery.build(api_service_name, api_version, developerKey=api_key)
# make a request (note, only the 'snippet' part has been requested)
request = youtube.playlistItems().list(part=['snippet'], playlistId=playlist_id)
response = request.execute()
# scrape out the actual video ids (probably could be safer)
for (k, v) in response.items():
if(k == 'items'):
video_ids = [pli['snippet']['resourceId']['videoId'] for pli in v if pli['snippet']['resourceId']['kind']=='youtube#video']
print(video_ids)

With the YouTube API v3 how can I get access to content duration, and genres? By search or get details

I tried to use this:
https://www.googleapis.com/youtube/v3/playlistItems?part=snippet,contentDetails&{playlist_id}&key={key}&maxResults=50
and
https://www.googleapis.com/youtube/v3/search?part=snippet&q=YouTube+Data+API&type=video&videoCaption=closedCaption&key={key}&maxResults=50
It says in the documentation it is contentDetails.duration but this doesn't seem to be present in the data I receive.
In order to get the detailed information about a video in a playlist, you will need to hit the Videos.list method for every video in that playlist with the snippet and contentDetails values for part:
Request:
HTTP GET https://www.googleapis.com/youtube/v3/videos?part=snippet%2C+contentDetails&id=AKiiekaEHhI&key={YOUR_API_KEY}
Response (for id=AKiiekaEHhI):
{
"kind": "youtube#videoListResponse",
"etag": "\"dhbhlDw5j8dK10GxeV_UG6RSReM/Qz22l3E04nR4kuY2SGE5M_d1BMM\"",
"pageInfo": {
"totalResults": 1,
"resultsPerPage": 1
},
"items": [
{
"kind": "youtube#video",
"etag": "\"dhbhlDw5j8dK10GxeV_UG6RSReM/8X_byN22HJTh5FJyoMH9bFGR_Og\"",
"id": "AKiiekaEHhI",
"snippet": {
"publishedAt": "2015-05-04T10:01:43.000Z",
"channelId": "UCkvdZX3SVgfDW8ghtP1L2Ug",
"title": "The Legend of Zelda: Majora's Mask With Glitches - Part 17: Going Against the Flow",
"description": "Follow me on Twitter! http://twitter.com/swordlesslink\n\nFollow me on TwitchTV for live video game streaming! http://twitch.tv/swordlesslink",
"thumbnails": {
"default": {
"url": "https://i.ytimg.com/vi/AKiiekaEHhI/default.jpg",
"width": 120,
"height": 90
},
"medium": {
"url": "https://i.ytimg.com/vi/AKiiekaEHhI/mqdefault.jpg",
"width": 320,
"height": 180
},
"high": {
"url": "https://i.ytimg.com/vi/AKiiekaEHhI/hqdefault.jpg",
"width": 480,
"height": 360
},
"standard": {
"url": "https://i.ytimg.com/vi/AKiiekaEHhI/sddefault.jpg",
"width": 640,
"height": 480
}
},
"channelTitle": "Swordless Link",
"categoryId": "20",
"liveBroadcastContent": "none",
"localized": {
"title": "The Legend of Zelda: Majora's Mask With Glitches - Part 17: Going Against the Flow",
"description": "Follow me on Twitter! http://twitter.com/swordlesslink\n\nFollow me on TwitchTV for live video game streaming! http://twitch.tv/swordlesslink"
}
},
"contentDetails": {
"duration": "PT17M30S",
"dimension": "2d",
"definition": "hd",
"caption": "false",
"licensedContent": true
}
}
]
}
The duration of the content can be found as the object for the duration key in the contentDetails dictionary.
The categoryId maps to your video category, which you will have to look up using the VideoCategories.list method.
Request:
HTTP GET https://www.googleapis.com/youtube/v3/videoCategories?part=snippet&id={CATEGORY_ID}&key={YOUR_API_KEY}
Response (for id=20:
{
"kind": "youtube#videoCategoryListResponse",
"etag": "\"dhbhlDw5j8dK10GxeV_UG6RSReM/cVclmqPmb6Xbwij8SctXRUrSVhw\"",
"items": [
{
"kind": "youtube#videoCategory",
"etag": "\"dhbhlDw5j8dK10GxeV_UG6RSReM/WmA0qYEfjWsAoyJFSw2zinhn2wM\"",
"id": "20",
"snippet": {
"channelId": "UCBR8-60-B28hp2BmDPdntcQ",
"title": "Gaming",
"assignable": true
}
}
]
}
The object for the title key in the snippet dictionary returns the String value of the video category that you want.
If you check search resource, you'll see its not in that response.
This was actually a feature request in: https://code.google.com/p/gdata-issues/issues/detail?id=4294
You can follow up that issue.

Get latest uploads using the v3 version of YouTube gData

Does anyone know how to get the latest uploads for a specific channel (or user will do too)?
In v2 of the gdata api you had the 'http://gdata.youtube.com/feeds/users/[username]/uploads?alt=json' call. But that's deprecated. In v3 there's the youtube.activities.list function, but that doesn't give the same results.
I thought I could get the playlists first, but than I seem to be missing some uploads that are not in a playlist.
Any suggestions?
To get the lastest uploads of a specific channel, don't pass by : youtube.activities.list.
The YouTube API V3 provide a special playlist of the uploads.
To get the id of the playlist two important link :
https://developers.google.com/youtube/v3/docs/channels/list?hl=fr
https://developers.google.com/youtube/v3/docs/playlistItems/list?hl=fr
And the two steps to get the uploads :
You need to use youtube.channel.list with the parameters :
part=contentDetails
id=ID_OF_THE_CHANNEL
The result is like this :
{
"kind": "youtube#channelListResponse",
"etag": "\"kjEFmP90GvrCl8BObMQtGoRfgaQ/CMNDR4CfkeuPx4qnAlqzH11BB5A\"",
"pageInfo": {
"totalResults": 1,
"resultsPerPage": 1
},
"items": [
{
"kind": "youtube#channel",
"etag": "\"kjEFmP90GvrCl8BObMQtGoRfgaQ/MeyW1Z8CbXCFwqPMlOLEwNZyMc0\"",
"id": "UCzOpxz1sdfp_0eRYqXkoSNA",
"contentDetails": {
"relatedPlaylists": {
"likes": "qsdqsxz1y8np_0eRYqXkoSNA",
"uploads": "qsdqsd1y8np_0eRYqXkoSNA"
},
"googlePlusUserId": "151...45515"
}
}
]
}
The playlist id of the uploads : items -> contentDetails -> uploads
Now you need to call the API a second time with youtube.playlistItems.list with the parameters :
part=snippet
playlistId=ID_OF_THE_PLAYLIST_UPLOADS
The result is like this :
{
"kind": "youtube#playlistItemListResponse",
"etag": "\"kjEFmP90GvrCl8BObMQtGoRfgaQ/bS4qNeqE0hEI-qb_r8hcbN9G1sE\"",
"nextPageToken": "CAUQAA",
"pageInfo": {
"totalResults": 38,
"resultsPerPage": 5
},
"items": [
{
"kind": "youtube#playlistItem",
"etag": "\"kjEFmP90GvrCl8BObMQtGoRfgaQ/ItttPAEwALDI0QdLoylbdN6oHcY\"",
"id": "UUT2INYKRKg8bTaC4Z8-faCKSOt7nfZDHN",
"snippet": {
"publishedAt": "2014-08-12T09:45:41.000Z",
"channelId": "UCM1Bnpxipb8H4GJoITnJ0XQ",
"title": "Trollsky making a small wood carving knife",
"description": "Music by Witek Kulczycki\nhttps://itunes.apple.com/pl/album/monaghan-single/id905434557\nhttp://www.cdbaby.com/Artist/WitekKulczycki",
"thumbnails": {
"default": {
"url": "https://i.ytimg.com/vi/bTD8U2fcG-Y/default.jpg",
"width": 120,
"height": 90
},
"medium": {
"url": "https://i.ytimg.com/vi/bTD8U2fcG-Y/mqdefault.jpg",
"width": 320,
"height": 180
},
"high": {
"url": "https://i.ytimg.com/vi/bTD8U2fcG-Y/hqdefault.jpg",
"width": 480,
"height": 360
},
"standard": {
"url": "https://i.ytimg.com/vi/bTD8U2fcG-Y/sddefault.jpg",
"width": 640,
"height": 480
}
},
"channelTitle": "Trollskyy",
"playlistId": "UUM1Bnpxipb8H4GJoITnJ0XQ",
"position": 0,
"resourceId": {
"kind": "youtube#video",
"videoId": "bTD8U2fcG-Y"
}
}
},
...
The uploads are sort by date. Lastest upload is the top of the list.
Hope it's help !

Returning duration while listing playlistItems?

I'm using this url:
https://www.googleapis.com/youtube/v3/playlistItems?
playlistId=FLFe0SGNFqZ9E2owO5ZDZpeg&
part=snippet,contentDetails,status
to fetch YouTube playlistItems.
I included all the part I'm interested in, however I found no way to return the duration of the item.
https://developers.google.com/youtube/v3/docs/playlistItems/list
Is this possible?
currently I'm getting back only an item like this:
{
"status": {
"privacyStatus": "public"
},
"kind": "youtube#playlistItem",
"contentDetails": {
"videoId": "tL-Ba86UhoE"
},
"snippet": {
"playlistId": "FLFe0SGeFqZ9E2owO5ZDZpwg",
"thumbnails": {
"default": {
"url": "https://i1.ytimg.com/vi/tL-BA86Uhoh/default.jpg",
"width": 120,
"height": 90
},
"high": {
"url": "https://i1.ytimg.com/vi/tL-BA86Uhoh/hqdefault.jpg",
"width": 480,
"height": 360
},
"medium": {
"url": "https://i1.ytimg.com/vi/tL-BA86Uhoh/mqdefault.jpg",
"width": 320,
"height": 180
}
},
"title": "Music Video",
"resourceId": {
"kind": "youtube#video",
"videoId": "tL-BA86Uhoh"
},
"channelId": "UCFe0SGNFqZ9E2owO5ZDZpwg",
"publishedAt": "2013-07-06T18:41:43.000Z",
"channelTitle": "channeltitle",
"position": 0,
"description": "Video for"
},
"etag": "\"ePFRUfYBkeQ2ncpP9OLHvB0fDw4/CJiCG6tvFw4quQlzJq3gTrhvCNo\"",
"id": "FL-fX6VqgtTfCJWKNE4aVRODKSrRgEdGvw"
},
With no time indication at all.
I'd rather avoid flooding YouTube with request to return a single video's duration.
Use link like this for get duration for many videos:
https://www.googleapis.com/youtube/v3/videos?part=contentDetails&id=idFirst,idSecond&key=YOUR_API_KEY
Use this Function : [ only used with Youtube Api v3 ]
Browser :
you have to make another http request
using :
https://www.googleapis.com/youtube/v3/videos?id={video id}&part=contentDetails&key={api Key}
and on
contentDetails
you will find the duration
Php :
function getDuration($apiKey,$video_id){
$link='https://www.googleapis.com/youtube/v3/videos?id='.$video_id.'&part=contentDetails&key='.$apiKey;
$data = json_decode(file_get_contents($link),true);
$duration = $data['items'][0]['contentDetails']['duration'];
return $duration;
}

Resources