YouTube API V3 recordingDetails object missing in the response - youtube-api

I have tried this YouTube API v3 call from curl today:
http://www.googleapis.com/youtube/v3/videos?id=ZCJgvabihQ8&key=apiKey&part=snippet,recordingDetails
Everything else is fine, but I didn't find the recordingDetails object in the response json:
{
"kind":"youtube#videoListResponse",
"etag":"\"oLweQuB9Vh7wAB9a0AIHg_K-wsM/EuRsJ-sxI3qstP1T58S5Qnb_NIg\"",
"items":[
{
"id":"ZCJgvabihQ8",
"kind":"youtube#video",
"etag":"\"oLweQuB9Vh7wAB9a0AIHg_K-wsM/CYNTRL05S4okPzkUfE5LbrRKt9g\"",
"snippet":{
"publishedAt":"2013-01-25T13:36:19.000Z",
"channelId":"UCpVm7bg6pXKo1Pr6k5kxG9A",
"title":"Weird Nature: Pink Dolphins?",
"description":"Up to 9 feet long and weighing up to 300 pounds, pink river dolphins are the largest freshwater dolphins in the world.",
"thumbnails":{
"default":{
"url":"https://i.ytimg.com/vi/ZCJgvabihQ8/default.jpg"
},
"medium":{
"url":"https://i.ytimg.com/vi/ZCJgvabihQ8/mqdefault.jpg"
},
"high":{
"url":"https://i.ytimg.com/vi/ZCJgvabihQ8/hqdefault.jpg"
}
},
"categoryId":"24"
}
}
]
}
Is there anything I missed? Many thanks.

recordingDetails is not public for all videos, so if a video doesn't have these attributes available, nothing will be returned. By not returning anything, YouTube saves bandwidth and the response time can be faster.
Original reponse:
This looks like a legitimate bug...
recordingDetails is listed as an option on the videos resource
overview page, but not listed as a valid part in the video list method
here: https://developers.google.com/youtube/v3/docs/videos/list
Normally when you try using an invalid part you get a "400 Bad
Request" error, but recordingDetails still returns a 200 response, so
it looks like it really is supposed to be returned...
You should submit a bug report here:
https://code.google.com/p/gdata-issues/issues/entry?template=YouTube%20(Defect%20Report)

recordingDetails will only be returned for videos that explicitly have either the geolocation or the recording time set.
(Not all videos set recording time; it's a distinct piece of metadata from publication time.)

You can do a list call to retrieve a list of videos based on a location and locationRadius.
Then, with the returned list you can do a videos call including all video IDs in the id parameter of the query. You can then specify recordingDetails as "part" and it will work.
This is how Youtube does it here:
https://github.com/youtube/geo-search-tool

Related

Youtube API videoEmbeddable filter not working? [duplicate]

I am using v3 api and videoEmbeddable="true" in my search request.
However, when I try to play the video(s) on my webpage, it says the content is blocked to be displayed on this site. Watch it on Youtube.
Is there a parameter that I can use which will not return non-embeddable videos?
*EDIT *
Video Response:
{u'items': [{u'snippet': {u'title': u'Jerez - Yamaha Preview'}, u'contentDetails': {u'definition': u'hd', u'contentRating': {u'ytRating': u'ytAllAudiences'}, u'caption': u'false', u'duration': u'PT1M21S', u'licensedContent': True, u'dimension': u'2d'}, u'status': {u'publicStatsViewable': True, u'privacyStatus': u'public', u'uploadStatus': u'processed', u'license': u'youtube', u'embeddable': True}, u'id': u'aaR72Xf_4wc'}]}
Query:
return yt_service_v3.videos().list(
id='aaR72Xf_4wc',
part="id,snippet,contentDetails,status",
fields="items(id,snippet(title),contentDetails,status)",
).execute()
This video is not embeddable on my webpage and in the response there is nothing to suggest that this video is not embeddable.
I request both contentDetails and status. I am not requesting via mobile device
Please provide pointers.
A small subset of videos have domain-level whitelists or blacklists applied to them by their content owners. Those restrictions are not reflected in API responses.
This is what you're seeing with aaR72Xf_4wc and the relevant portion of the blog post about playback restrictions is
There are even more subtle restrictions that occasionally come into
play. Not all of these are currently queryable via the API. For
instance, some videos are only playable on a certain set of domains.
I assume it wasn't there 2.5 years ago, but the current API does have indication for regional block, when requesting contentDetails. here's a response for such request for 2 videos, the first one is blocked and the second one is not. Note the regionRestriction key:
{u'etag': u'"iDqJ1j7zKs4x3o3ZsFlBOwgWAHU/ZqEbAZJ-JFnYX3v37ZRuhK8FFN8"',
u'items': [{u'contentDetails': {u'caption': u'false',
u'definition': u'sd',
u'dimension': u'2d',
u'duration': u'PT2M5S',
u'licensedContent': False,
u'regionRestriction': {u'blocked': [u'NU',
u'BY',
u'NP',
u'NR',
u'WS',
u'TD',
u'SY',
u'NZ',
u'NE',
.
.
.
u'TG']}},
u'etag': u'"iDqJ1j7zKs4x3o3ZsFlBOwgWAHU/hM4srkgNUiZj2GtAhLDFoFrHnlk"',
u'id': u'WGf4mSBoCzQ',
u'kind': u'youtube#video'},
{u'contentDetails': {u'caption': u'false',
u'definition': u'sd',
u'dimension': u'2d',
u'duration': u'PT17M2S',
u'licensedContent': False},
u'etag': u'"iDqJ1j7zKs4x3o3ZsFlBOwgWAHU/JNjXh3lMwcaC9gtbzM-KmOQLh44"',
u'id': u'Tw75Dt8fBBs',
u'kind': u'youtube#video'}],
u'kind': u'youtube#videoListResponse',
u'pageInfo': {u'resultsPerPage': 2, u'totalResults': 2}}
You can also filter by syndication if you are accessing from a mobile device. Last but not the least there are region specific blockages.
Maybe you need to also include the filter for videoSyndicated. I don't know for sure though; it's a little confusing to me.

YouTube IFrame Player API getVideoData is removed: how to get title?

On November 13th, I got a call from a customer reporting that the YouTube player didn't work anymore. After a quick look in the dev tool, I found that there was an error:
Uncaught TypeError: a.getVideoData is not a function
Looking into what the player object was containing, I learned that there's no function getVideoData anymore.
The function getVideoData provided a way to get the video title. Now, how can I get the title?
Is there any article from Google about this change?
To get a video's title, you can query the YouTube Data API v3:
GET https://www.googleapis.com/youtube/v3/videos
?part=snippet
&id=VIDEO_ID
&key=YOUR_API_KEY
For that you need to sign up on the Google Cloud Console and create an API key (it's free). You can restrict the API key to only be used from your website, that way you can safely make it public in your JS source code/html code without others being able to make queries on your behalf. Make sure to enable the YouTube Data API v3 in the console as well, otherwise your queries will return errors.
The above query will return a JSON representation of the information on the video that you are interested in (the snippet part). Say you parse the JSON into an object called result. Then you can get the video title via
result.items[0].snippet.title
getVideoData() seems to be back (Dec, 2017). So, try again !
As of today (October 1st, 2020), I am retrieving the title of the video from within YouTube's API object:
// Assigning YouTube's ID to your ID variable
const playerID = "xxxxxxx";
// Creating an object for the video using YouTube's API.
const yPlayer = new YT.Player(playerID, {
events: {
'onReady': onPlayerReady(),
'onStateChange': onPlayerStateChange()
}
});
function onPlayerReady() {
}
function onPlayerStateChange() {
// Title retrieved here
let videoTitle = yPlayer.j.videoData.title;
}
onYouTubeIframeAPIReady();

Youtube API 3 get latest videos

So I am trying to grab 10 latest videos from user uploads.
Now the only problem is that the only date visible in the playlistitems request is publishedAt which is the date when the video was uploaded
- not the date of when it was made public, which makes a huge difference.
I noticed that I can grab the correct date via the video request, but it just does not seem to be the best place to do it.
Let me show you an example of what I am dealing with.
Let's take Maroon5 channel.
forUserName: Maroon5VEVO
GET https://www.googleapis.com/youtube/v3/channels?part=contentDetails&forUsername=Maroon5VEVO&key={YOUR_API_KEY}
https://developers.google.com/youtube/v3/docs/channels/list#try-it
Here is where we grab the:
uploadsId: UUN1hnUccO4FD5WfM7ithXaw
So we can query:
GET https://www.googleapis.com/youtube/v3/playlistItems?part=snippet&playlistId=UUN1hnUccO4FD5WfM7ithXaw&maxResults=50&key={YOUR_API_KEY}
https://developers.google.com/youtube/v3/docs/playlistItems/list#try-it
and then we can have a look at some videos.
Let's grab the latest one. For me it is this one:
"title": "Maroon 5 - This Summer's Gonna Hurt Like A ... (Explicit)",
"videoId": "Wa64gOwuIyE"
And most importantly :
"publishedAt": "2015-06-01T17:41:58.000Z",
Now let's grab more details of this video, by running this query:
GET https://www.googleapis.com/youtube/v3/videos?part=snippet&id=Wa64gOwuIyE&key={YOUR_API_KEY}
https://developers.google.com/youtube/v3/docs/videos/list#try-it
Here we get more detailed view with a date that is ... different !
"publishedAt": "2015-06-01T20:00:01.000Z",
That means that the publishedAt date in playlists is actually the date of the upload - not when the video was made public.
In our list of 10 latest items we want the LATEST published videos , and not latest uploaded vids.
If you know a way how to approach it , please share.
Here is my snippet for now (working with a wrong publishedAt date)
$.get(
"https://www.googleapis.com/youtube/v3/playlistItems",{
part : 'snippet',
maxResults : 10,
playlistId : UPLOADS_PID,
key: YOUR_API_KEY},
function(data) {
$.each( data.items, function(i, item ) {
(...)
});
}
);
I believe you can use /search endpoint. As you want to grab 10 latest videos from user uploads, you can use channel id instead of playlist id.
Request:
GET https://www.googleapis.com/youtube/v3/search?part=snippet&channelId={CHANNEL_ID}&maxResults=10&order=date&type=video&key={YOUR_API_KEY}

Is there a YouTube API that can give me structured metadata about a video?

Using the YouTube API, how can I fetch structured data about a video? For instance, given a video that is a movie trailer, how can I find the movie title or topic in a structured format, and other interesting metadata such as the celebrities featured or the director?
Yes. The v3 API allows you do do this via videos/list. Here's an example API call using a trailer for The Dark Knight Rises:
GET https://www.googleapis.com/youtube/v3/videos?part=topicDetails&id=g8evyE9TuYk&fields=items%2FtopicDetails%2FtopicIds&key={YOUR_API_KEY}
(To get a developer key, follow the instructions in our video tutorial).
That sets:
topic: topicDetails
id: g8evyE9TuYk
fields: items/topicDetails/topicIds
In the response body, you get:
{
"items": [
{
"topicDetails": {
"topicIds": [
"/m/0bpm4yw",
"/m/01d5g",
"/m/0btpm6",
"/m/0184dt",
"/m/02vxn"
]
}
}
]
}
These correspond to Freebase mids, which you can lookup using the Freebase API. For instance, the first response corresponds to the Freebase entity The Dark Knight Rises (movie). Once you look up the entity, you can look up related entities such as the director, actors, or genre.
Play around with the API explorer a bit. When you're ready to translate this into code, watch out video about turning the API reference into code.
I found that I got the metadata details I wanted via this request url:
https://www.googleapis.com/youtube/v3/videos?part=snippet,contentDetails&id={YouTubeVideoID}&key={YourAPIkey}
Here is documentation with description of all the returned data fields.
Here's info on how to get an API key.

v3 api returns blocked content even with videoEmbedable = True

I am using v3 api and videoEmbeddable="true" in my search request.
However, when I try to play the video(s) on my webpage, it says the content is blocked to be displayed on this site. Watch it on Youtube.
Is there a parameter that I can use which will not return non-embeddable videos?
*EDIT *
Video Response:
{u'items': [{u'snippet': {u'title': u'Jerez - Yamaha Preview'}, u'contentDetails': {u'definition': u'hd', u'contentRating': {u'ytRating': u'ytAllAudiences'}, u'caption': u'false', u'duration': u'PT1M21S', u'licensedContent': True, u'dimension': u'2d'}, u'status': {u'publicStatsViewable': True, u'privacyStatus': u'public', u'uploadStatus': u'processed', u'license': u'youtube', u'embeddable': True}, u'id': u'aaR72Xf_4wc'}]}
Query:
return yt_service_v3.videos().list(
id='aaR72Xf_4wc',
part="id,snippet,contentDetails,status",
fields="items(id,snippet(title),contentDetails,status)",
).execute()
This video is not embeddable on my webpage and in the response there is nothing to suggest that this video is not embeddable.
I request both contentDetails and status. I am not requesting via mobile device
Please provide pointers.
A small subset of videos have domain-level whitelists or blacklists applied to them by their content owners. Those restrictions are not reflected in API responses.
This is what you're seeing with aaR72Xf_4wc and the relevant portion of the blog post about playback restrictions is
There are even more subtle restrictions that occasionally come into
play. Not all of these are currently queryable via the API. For
instance, some videos are only playable on a certain set of domains.
I assume it wasn't there 2.5 years ago, but the current API does have indication for regional block, when requesting contentDetails. here's a response for such request for 2 videos, the first one is blocked and the second one is not. Note the regionRestriction key:
{u'etag': u'"iDqJ1j7zKs4x3o3ZsFlBOwgWAHU/ZqEbAZJ-JFnYX3v37ZRuhK8FFN8"',
u'items': [{u'contentDetails': {u'caption': u'false',
u'definition': u'sd',
u'dimension': u'2d',
u'duration': u'PT2M5S',
u'licensedContent': False,
u'regionRestriction': {u'blocked': [u'NU',
u'BY',
u'NP',
u'NR',
u'WS',
u'TD',
u'SY',
u'NZ',
u'NE',
.
.
.
u'TG']}},
u'etag': u'"iDqJ1j7zKs4x3o3ZsFlBOwgWAHU/hM4srkgNUiZj2GtAhLDFoFrHnlk"',
u'id': u'WGf4mSBoCzQ',
u'kind': u'youtube#video'},
{u'contentDetails': {u'caption': u'false',
u'definition': u'sd',
u'dimension': u'2d',
u'duration': u'PT17M2S',
u'licensedContent': False},
u'etag': u'"iDqJ1j7zKs4x3o3ZsFlBOwgWAHU/JNjXh3lMwcaC9gtbzM-KmOQLh44"',
u'id': u'Tw75Dt8fBBs',
u'kind': u'youtube#video'}],
u'kind': u'youtube#videoListResponse',
u'pageInfo': {u'resultsPerPage': 2, u'totalResults': 2}}
You can also filter by syndication if you are accessing from a mobile device. Last but not the least there are region specific blockages.
Maybe you need to also include the filter for videoSyndicated. I don't know for sure though; it's a little confusing to me.

Resources