Identify a video as an ad with YouTube Data API - youtube

I'm using mostly the video and search list resource types. I want to filter the results for video ads. I had hoped that ads would be a video category or there would be another identifier for video ads, but I haven't been able to find a way so far. Any ideas?

With my open-source YouTube operational API you have access to whether or not a given video is a paid promotion by fetching the isPaidPromotion boolean in the JSON file at https://yt.lemnoslife.com/videos?part=isPaidPromotion&id=VIDEO_ID
Here are examples of videos ids:
having paid promotion: Q6gtj1ynstU
not having paid promotion: PEorJqo2Qaw
Then you have to discover all YouTube videos, to do so except if you look for specific keywords etc, there is this difficult method which consists in getting an initial set of YouTube channels, fetching their videos, fetching the comments on each video, fetching the YouTube channels from the comments and so on.

Unfortunately (AFAIK), some of those ads videos are unlisted videos - see these (1 and 2) ads videos examples I extracted while watching a random YouTube video - this ads video is public, though.
While querying the data of one of these videos (i.e. uuh2wkRmodI) - see the example using the try-it feature in the API documentation - , I don't see any relevant information that points me this is an advertisement video - other than being an unlisted video.
Probably, you can consider its statistics - I found odd that a video has no likes, no favorites no comments AND has views:
"statistics": {
"viewCount": "32",
"likeCount": "0",
"favoriteCount": "0",
"commentCount": "0"
}
Since those are unlisted ads videos, those cannot be searched via the API. Quote:
If a video is uploaded as an unlisted video, the property value also
specifies the date and time that the video was uploaded. In this case,
anyone who knows the video's unique video ID can retrieve the video
metadata.
Unless you somehow manages to get the VIDEO_IDs of those ads appearing before a normal video starts, you cannot really search those videos neither by YouTube or its API.
My additional guess is also those ads videos are set by YouTube itself based (aside other settings) in the region (country) of the viewer and the owner of those ads videos pays to YouTube for embed their advertisements.
If you want to try it out, then, try to search for videos that came from channels of recognized product brands and get only their public and kind of short videos (I'm not talking abuot #shorts, but, videos with a duration of a half on a minute or less).
Additionally, take into account that some ads videos might be longer, so, in resume: you have to work with what is publicly available.

Related

Detect whether a Youtube video is licensed or not

So I got the new API cURL working for me for requesting video informations, I want to get the "licensed" info, tried with a music video, it worked, here.
My problem here is that I even tried it with a normal video, I got the same "licensedContent": true How can I detect if the music video is actually licensed?
For an example here is shakira's song and the description of the license here.
Disclaimer:
The following answer isn't complying with the YouTube operational API specification, you should instead follow my other StackOverflow answer on enumerating the musics in the given video. That way by checking whether or not the video contains musics you can deduce if the video is licensed or not.
Deprecated answer:
One more time YouTube Data API v3 doesn't provide a basic feature.
I recommend you to use my open-source YouTube operational API. Indeed by requesting https://yt.lemnoslife.com/videos?part=containsMusic&id=VIDEO_ID you'll get the boolean whether or not the video contains a music in item["containsMusic"].
Examples:
Hips don't lie:
https://yt.lemnoslife.com/videos?part=containsMusic&id=DUT5rEU6pqM
(returning "containsMusic": true)
A not music
video:
https://yt.lemnoslife.com/videos?part=containsMusic&id=6ZRgVX8SYX4
(returning "containsMusic": false)
licensedContent
means that the content was uploaded to a channel linked to a YouTube content partner and then claimed by that partner.
https://developers.google.com/youtube/v3/docs/videos#contentDetails.licensedContent

How to get metrics from YouTube Analytics API for every video which belongs to current user?

I want to get metrics (such as likes, views and subscribers gained) for every video in my youtube channel (or about 10 latest video) , how can I do it correctly?
I'm using such API call from Youtube Analytics API, but it turns out that it returns total views and total likes from all videos, not individually about every video.
`https://youtubeanalytics.googleapis.com/v2/reports?metrics=views,likes,subscribersGained&ids=channel==MINE&startDate=2014-07-03&endDate=2020-06-01&&key=${apiKey}&access_token=${token}`
I read documentation of YouTube Analytics API and I can't find this information there.
If you want the response to be grouped by video your have to specify the dimension parameter to video.
Here is a sample request from the documentation (Basic stats/Top 10 – Most watched videos for a channel):
https://developers.google.com/youtube/analytics/sample-requests#Channel_Reports
Although the note does not specify it, the sort parameter must be the first metric that you declared.
If want to get information on more that 10 videos or to pull information for the latest videos, you can specify the dimension as video and you must specify the video ids in the filter parameter as video==VIDEO1_id,VIDEO2_id....
The videos in a channel can be retrieved through the YouTube Data API from the search endpoint.
You will get a list of videos with their details as a response, among others the videoId and publishedAt values.

Get list of videos uploaded before and after certain video

Youtube use to have a feature where you could click a more videos button while watching any video, and see a snapshot of the uploads playlist with videos uploaded before and after the one you are currently watching.
I am trying to get a list like that with the v3 data API and it seems there is no way. There use to be a way to dictate an index when using the playlistItems call, but now there isn't.
If you go to a channels upload playlist and click play all, you can see a list of videos surrounding the one you are watching, so it seems this functionality is possible, but I don't know how they are doing it.
Any ideas?

Is it possible to add a video on youtube but only display it on your website?

I basically want to make a video "private", but then use some code to display it public on my site. Is that possible?
It seems like "unlisted" is what I want. According to this article:
An unlisted video is a different type of private video. "Unlisted" means that only people who know the link to the video can view it (such as friends or family to whom you send the link). An unlisted video will not appear in any of YouTube's public spaces (such as search results, your channel, or the Browse page). An unlisted video is different to a private video in these ways: you don't need a YouTube account to watch the video (you can see an unlisted video if someone sends you the video's link) there's no 25 person sharing limit
Still not sure if this is really going to help me keep prying eyes away from the video, but for now, it seems to do what I want.

Google Play Web Video Player API

Is there an API for the Google Play online video playback of content? Would the YouTube API work?
I am wanting to embed Google Play content into a website I am building.
Thank you,
Joseph Irvine
Google Play movie purchases and rentals do also show up as YouTube videos (with a unique YouTube video ID), and so it is possible; obviously, you'd need to use oAuth2 authentication so when a user logs in, YouTube can verify that the user has the permission to see that film/TV show.
The real trick, however, is getting the right YouTube ID. They show up through search results via the search endpoint (so, for example, https://www.googleapis.com/youtube/v3/search?part=snippet&q=Monsters+University&key={YOUR_API_KEY} would be such a search), but that endpoint only gives you access to the "snippet" content type, which doesn't include the parameter "licensedContent" to let you know if it's a for-pay video (that parameter is found in the "contentDetails" type, which is only available from a video list call).

Resources