liveStreamingDetails for playlistItems YouTube Data API v3 - youtube-api

I am looking for a way to detect if a video is a live stream. The YouTube Data API has a property liveStreamingDetails when using its Videos.list endpoint.
However this is not present when using the PlaylistItems.list endpoint.
Obviously I am not going to make another call (after PlaylistItems.list) just to get this property. Is there a way to find out what video from PlaylistItems.list is a live stream?

Unfortunately, the answer to your question is negative:
As per the official specification, the response returned by the PlaylistItems.list API endpoint is a JSON object of which items property is an array of PlaylistItems Resource objects:
{
"kind": "youtube#playlistItem",
"etag": etag,
"id": string,
"snippet": {
"publishedAt": datetime,
"channelId": string,
"title": string,
"description": string,
"thumbnails": {
(key): {
"url": string,
"width": unsigned integer,
"height": unsigned integer
}
},
"channelTitle": string,
"videoOwnerChannelTitle": string,
"videoOwnerChannelId": string,
"playlistId": string,
"position": unsigned integer,
"resourceId": {
"kind": string,
"videoId": string,
}
},
"contentDetails": {
"videoId": string,
"startAt": string,
"endAt": string,
"note": string,
"videoPublishedAt": datetime
},
"status": {
"privacyStatus": string
}
}
This object contain only a limited amount of metadata info attached to the video items the PlaylistItems.list endpoint provides back.
Consequently, you have to acknowledge that, if needing the liveStreamingDetails property attached to videos returned by PlaylistItems.list, you have to request this info from the Videos.list API endpoint separately: query this latter endpoint by passing to its request parameter id a comma-separated list made of the IDs of the videos of your interest (but no more than 50 of them).
Do note that each Videos.list endpoint call is very cheap: it has attached a quota cost of only one unit, irrespective of the number of video IDs passed on to it.

Related

YouTube API Returns Wrong SubscriberCount

I have two channels examples:
https://www.youtube.com/channel/UC56eaiucsjSfKgevcaGcn2w => real sub 150k
https://www.youtube.com/channel/UC-2Zibu3OGJdIisYaODXhbQ => real sub 208k
This is what was returned from the Channels list endpoint:
{
"kind": "youtube#channelListResponse",
"etag": "wVkhi3RvF1ayB9ou0W6KZcanGZE",
"pageInfo": {
"totalResults": 2,
"resultsPerPage": 5
},
"items": [
{
"kind": "youtube#channel",
"etag": "QI30osPYB_sy-uwNipgDhEPKRso",
"id": "UC56eaiucsjSfKgevcaGcn2w",
"statistics": {
"viewCount": "17359612",
"subscriberCount": "320",
"hiddenSubscriberCount": false,
"videoCount": "26"
}
},
{
"kind": "youtube#channel",
"etag": "IjATUKKNgPUxmtHQWicg_r22hqc",
"id": "UC-2Zibu3OGJdIisYaODXhbQ",
"statistics": {
"viewCount": "1723670",
"subscriberCount": "18",
"hiddenSubscriberCount": false,
"videoCount": "1"
}
}
]
}
When you go to the links above, and navigate through the channel, I noticed that the channel Id changes and the API returns the correct sub count for the new Id.
I am unsure how a unique video Id can be linked to more than one channel, What kind of channels are these? merged, linked, or something else? and how does the user do this?
"click on the same link you gave me, then click on the first video" there isn't any video on my side. Using PlaylistItems: list with the channel uploads playlist I get 26 videos and the first one is hVyJsXCXyuo. Even if all retrieved videos are unavailable, for the first video I indeed see that the channel real subscribers count is 150k and if I click on the channel name I get redirected to another channel that is UC4LyPYXnF07KF97Nb8vE_Pg which indeed has 150k subscribers.
Then you can use Channels: list to get the correct subscriber count using id=UC4LyPYXnF07KF97Nb8vE_Pg cf https://www.googleapis.com/youtube/v3/channels?part=statistics&id=UC4LyPYXnF07KF97Nb8vE_Pg&key=YOUR_API_KEY
Note that under a video the channel id you are redirected to seems to differ if you click on the channel avatar or the channel name on a desktop. The following redirection are done if you are on a phone or a computer and if you click on the channel avatar or channel name:
Phone:
Name: UC56eaiucsjSfKgevcaGcn2w
Avatar: UC56eaiucsjSfKgevcaGcn2w
Computer:
Name: UC4LyPYXnF07KF97Nb8vE_Pg
Avatar: UC56eaiucsjSfKgevcaGcn2w

What is the difference between ContentDetails.RegionRestriction and ContentDetails.CountryRestriction in the Youtube API V3?

Below I have my simple request that retrieves contentDetails for a specific video.
var youTubeService = new YouTubeService(new BaseClientService.Initializer()
{
ApiKey = "your-apikey",
ApplicationName = "DIGITAL.CLI"
});
var channelsListRequest = new VideosResource.ListRequest(youTubeService, "contentDetails");
channelsListRequest.Id = "FakBv-xNTeU";
var response = channelsListRequest.Execute();
Console.WriteLine(JsonConvert.SerializeObject(response));
In the response I get a list of regions where the video is blocked, but there is also a section that isn't in the response called countryRestrictions.
{
"etag": "8Dlzw_juiiGAkJUxdgfegatGe34",
"items": [
{
"contentDetails": {
"caption": "false",
"contentRating": {},
"definition": "hd",
"dimension": "2d",
"duration": "PT1M37S",
"licensedContent": true,
"projection": "rectangular",
"regionRestriction": {
"blocked": [
"US",
"FM",
"MP",
"VI",
"GU",
"MH",
"PR",
"PW",
"AS",
"UM"
]
}
},
"etag": "-DZJdN2PuXnNfuceW0s7RVa4Y9I",
"id": "FakBv-xNTeU",
"kind": "youtube#video"
}
],
"kind": "youtube#videoListResponse",
"pageInfo": {
"resultsPerPage": 1,
"totalResults": 1
}}
So this video has regionRestrictions, but no country restrictions. Is countryRestrictions still in use? The client library documentation of VideoConntentDetails has the same description for both of them.
And as a bonus question, if the allowed list contains items, then does that mean that all countries not in the allowed list are blocked?
According to the client library documentation of VideoContentDetailsRegionRestriction, this model class is deprecated; thus the client library property regionRestriction is deprecated too.
The client library is mapping its property countryRestriction from the YouTube Data API's property contentDetails.regionRestriction.
According to the official specification of the YouTube Data API's Videos resource, there's no property countryRestriction that this kind of API resource contains.
The answer to your second question is: yes, all countries not in the allowed list are blocked (the emphasis below is mine):
contentDetails.regionRestriction.allowed[] (list)
A list of region codes that identify countries where the video is viewable. If this property is present and a country is not listed in its value, then the video is blocked from appearing in that country. If this property is present and contains an empty list, the video is blocked in all countries.

is there Youtube API support to retrieve my statistics like if I watched it or not

is there Youtube API support to retrieve my statistics like if I watched it or not, how many times I played it or retrieve my view history? I spend some time going thru the Youtube Data API but no luck.
You can use YouTube API - ViewCount to retrieve the number of times the video has been viewed. You can retrieve the information in the client side or in the server side using some of the libraries.
You need to retrieve the video, from there you can retrieve the statistics part contains the viewCount
Sample request:
GET https://www.googleapis.com/youtube/v3/videos?part=statistics&id=Q5mHPo2yDG8&key={YOUR_API_KEY}
Response:
200 OK
- Show headers -
{
"kind": "youtube#videoListResponse",
"etag": "\"g-RLCMLrfPIk8n3AxYYPPliWWoo/dZ8K81pnD1mOCFyHQkjZNynHpYo\"",
"pageInfo": {
"totalResults": 1,
"resultsPerPage": 1
},
"items": [
{
"id": "Q5mHPo2yDG8",
"kind": "youtube#video",
"etag": "\"g-RLCMLrfPIk8n3AxYYPPliWWoo/4NA7C24hM5mprqQ3sBwI5Lo9vZE\"",
"statistics": {
"viewCount": "36575966",
"likeCount": "127569",
"dislikeCount": "5715",
"favoriteCount": "0",
"commentCount": "20317"
}
}
]
}

How to get subscriber count and videos count for a given YouTube channel?

Until now I've been using this URL to retrieve subscriber count for a channel:
http://gdata.youtube.com/feeds/api/users/<channel_id>?v=2&alt=json
And this URL to get channel videos count:
https://gdata.youtube.com/feeds/api/users/<channel_id>/uploads?v=2&alt=jsonc&max-results=0
But from this day Google discontinued using it's v2 API and I can't find replacement options for this data.
You're going to want to use the Channels/list endpoint as pass in statistics for the part parameter.
Request:
HTTP GET: GET https://www.googleapis.com/youtube/v3/channels?part=statistics&id={CHANNEL_ID}&key={YOUR_API_KEY}
Response (with id=UCt7iVnJwjBsof8IPLJHCTgQ):
{
"kind": "youtube#channelListResponse",
"etag": "\"dhbhlDw5j8dK10GxeV_UG6RSReM/WNxXCvycTyqTjTn9sLJ5toVjBRY\"",
"pageInfo": {
"totalResults": 1,
"resultsPerPage": 1
},
"items": [
{
"kind": "youtube#channel",
"etag": "\"dhbhlDw5j8dK10GxeV_UG6RSReM/jijTuA_iWn2Kv9aRnqeAWNAcQ6I\"",
"id": "UCt7iVnJwjBsof8IPLJHCTgQ",
"statistics": {
"viewCount": "796662",
"commentCount": "20",
"subscriberCount": "257",
"hiddenSubscriberCount": false,
"videoCount": "126"
}
}
]
}
You can pass in a comma-separated list of Channel IDs for the id parameter. Because I only passed in one id, the first object of the items array will have the values you need. Get the object for the subscriberCount and videoCount values in the statistics dictionary for the data you want.

Get daily view counts for all video of a given channel on Youtube Analytics

I'm trying to use the Youtube Analytics API to gather daily view counts for all the videos in my channel. It seems like the video dimension throttles the result at top 10 only. Is there anyway I could get daily view count for all my videos?
At the moment you cannot get metrics for all videos via Analytics API directly. First you need to fetch the ids of all your videos and then request Analytic's data for each. I managed it this way:
Get the playlist ID for your uploaded videos via Data API https://www.googleapis.com/youtube/v3/channels?part=contentDetails&mine=true&maxResults=25&access_token=[TOKEN]. Gives you this result:
{
"kind": "youtube#channelListResponse",
"etag": "\"F9iA7pnxqNgrkOutjQAa9F2k8HY/SAGx1pv6myGXge51dmywGW81h8o\"",
"pageInfo": {
"totalResults": 1,
"resultsPerPage": 1
},
"items": [
{
"kind": "youtube#channel",
"etag": "\"F9iA7pnxqNgrkOutjQAa9F2k8HY/g5zJtodBJms3CAfwF_ar2nVgJjU\"",
"id": "[id]",
"contentDetails": {
"relatedPlaylists": {
"likes": "[id]",
"favorites": "[id]",
"uploads": "[id]",
"watchHistory": "[id]",
"watchLater": "[id]"
},
"googlePlusUserId": "[id]"
}
}
]
}
Get all ids of your uploaded videos with the upload playlist id via Data API: https://www.googleapis.com/youtube/v3/playlistItems?part=id&pageToken=&playlistId=[UPLOADID]&maxResults=50&access_token=[TOKEN]. Note: You have to page through the results with nextPageToken.
With the collected video ids you can make a batch request to the Analytics API https://www.googleapis.com/youtube/analytics/v1/reports?ids=channel==mine&start-date=2014-12-29&end-date=2015-01-05&metrics=views,likes&dimensions=video,day&filters=video==[videoId],[videoId],[videoId],[...]&sort=video&access_token=[TOKEN] Note: You can batch up to 200 Video Ids.

Resources