Given a YouTube video, programmatically get its channel? - youtube

I've found at least five Stack Overflow questions of the form "here is a YouTube channel, how do I programmatically obtain the videos on this channel?"
I want to do the opposite: given a video, what channel did it come from?
So far, I've looked for solutions on this in the official YouTube API. I've also looked at libraries like pafy. No luck so far.

https://developers.google.com/youtube/v3/docs/videos/list
It looks like you can make a video request, then set:
part=snippet
This will return the channelId, among other things. I did a request like so:
GET https://www.googleapis.com/youtube/v3/videos?part=snippet&id=f8WsO__XcI0&key={YOUR_API_KEY}
and I get the response:
{
...
"items": [
{
"kind": "youtube#video",
"etag": "\"IHLB7Mi__JPvvG2zLQWAg8l36UU/Xn3r39kJJF0iqtZbqFIeFUTgC0Q\"",
"id": "f8WsO__XcI0",
"snippet": {
"publishedAt": "2015-04-13T21:20:53.000Z",
"channelId": "UC6nSFpj9HTCZ5t-N3Rm3-HA",
...
}

Related

how to map youtube handles to channel IDs

Youtube recently rolled out handles feature where they gave users youtube.com/#xxx type usernames, when visited these URLs show user's channel but I can't find any documentation or reference in API repositories.
How to extract youtube user channel ID from their handle?
One more time YouTube Data API v3 doesn't provide a basic feature.
I recommend you to try out my open-source YouTube operational API. Indeed by fetching https://yt.lemnoslife.com/channels?handle=#HANDLE you will get the YouTube channel id you are looking for in item["id"].
For instance with the YouTube channel handle #WHO, you would get:
{
"kind": "youtube#channelListResponse",
"etag": "NotImplemented",
"items": [
{
"kind": "youtube#channel",
"etag": "NotImplemented",
"id": "UC07-dOwgza1IguKA86jqxNA"
}
]
}

Retrieve the subscribers id who watched video

Overall Goal: To report possible subscribers who are not active on my YouTube channel.
I'm reading through the YouTube Data API (v3) trying to understand how to retrieve the actual ids who watched a specific video. I know you can get the number of views, but I don't see any call/response that shows you the subscriber ids. Has anyone done this?
So far what I gathered from the docs and Google searching is that this was possible using the Watch History of a subscriber, but that's been deprecated.
Thanks in advance!
So I do not believe it's possible to get IDs of users who have watched certain videos but I have a workaround for my use case; reporting inactive subscribers. This is not the best but it'll get me somewhere.
YouTube's API is very limiting now, but by calling the Subscriptions API
https://www.googleapis.com/youtube/v3/subscriptions?part=snippet%2CcontentDetails&mySubscribers=true&key=[YOUR_API_KEY]
I am able to get all subscribers with their channel IDs. Then after saving their IDs, I can check each one's statistics by making this call:
https://www.googleapis.com/youtube/v3/channels?part=statistics&id=[SUB_ID]&key=[YOUR_API_KEY]
which I receive a response like this:
{
"kind": "youtube#channelListResponse",
"etag": "\"j6xRRd8dTPVVptg711_CSPADRfg/AZpZT_vQrY3UTi57ia_QqrKdc8c\"",
"pageInfo": {
"totalResults": 1,
"resultsPerPage": 1
},
"items": [
{
"kind": "youtube#channel",
"etag": "\"something\"",
"id": "[SUB_ID]",
"statistics": {
"viewCount": "0",
"commentCount": "0",
"subscriberCount": "1",
"hiddenSubscriberCount": false,
"videoCount": "0"
}
}
]
}
Using this response (see "statistics"), I am making a generalization that if the subscriber has no comments AND no videos, then it's a safe bet that they are not active.

get the title on live video in youtube using API YouTube V3

i am using API Live Streaming youtube to retrieve list of live chat messages on youtube video using id_video, exits serveral properties that appear in this resource such as snippet.liveChatId, snippet.displayMessage which i can found them from this ressource,
so my question is how can i get the title on live video in channel youtube which is not for me ?
thanks
You may want to check this documentation. The items[] property will return a list of live streams that match the request criteria.
{
...
},
"items": [
liveStream Resource
]
}
The following JSON structure shows the format of a liveStreams resource:
{
"kind": "youtube#liveStream",
"etag": etag,
"id": string,
"snippet": {
"publishedAt": datetime,
"channelId": string,
"title": string,
"description": string,
"isDefaultStream": boolean
},
...
}

Youtube API get a video?

I am trying to get a simple thing - a video, and i just can't understand why such a simple thing, is not clearly defined in the API docs.
To search for a video i have :
https://www.googleapis.com/youtube/v3/search?part=snippet&q=guy&key=api key
Than , i get the json, with results like :
"kind": "youtube#searchListResponse",
"etag": "\"MmqJLb8ZBOWRQIsg7xej7lrKLMI/_yCHjN-Yei6to4bLpd2j603Ea18\"",
"nextPageToken": "CAUQAA",
"pageInfo": {
"totalResults": 223929,
"resultsPerPage": 5
},
"items": [
{
"kind": "youtube#searchResult",
"etag": "\"MmqJLb8ZBOWRQIsg7xej7lrKLMI/ruSBEQPUZp3DX2M8M4bcCPny2fc\"",
"id": {
"kind": "youtube#video",
"videoId": "J0tGubH9ZyM"
},
What should i do now, to retrieve this first video ? i just need to get the link to the video with the video id, (or etag ? )
How the next request should look like ?
If all you want is a URL for the video (at youtube's page), it takes this form:
https://www.youtube.com/watch?v={videoId}
If you're instead looking to embed the video on your page, you could either do so with the embed code, which you can get with this call:
https://www.googleapis.com/youtube/v3/videos?part=player&id={videoId}&key=api key
Or with the iFrame API, which you can read about here:
https://developers.google.com/youtube/iframe_api_reference

What is difference of "Posted video" and "Uploads" in YouTube Channel? And how to get them through YouTube Data v3 API?

I am in the middle of developing a YouTube client using YouTube Data v3 API, and is playing with two different channels observed:
Go Pro Channel: https://www.youtube.com/user/GoProCamera/videos
YouTube curated Sports Channel: https://www.youtube.com/channel/UCEgdi0XIXXZ-qJOFPf4JSKw/videos
In Go Pro channel, I can also choose a video filter: "Uploads", "Liked" and "Posted Videos". I am much puzzled by the "Uploads" and "Posted Videos" filter, which from my observation, on this channel, they are giving the same result. But in YouTube curated sports channel, there is only "Posted Video" option there.
For the past hours, I can not find any definitive explanation from YouTube v2/v3's API documentation, and what is more bothering me is, I can not find any API to retrieve the video entry data in those channels.
For Go Pro Channel, I could at least rely on the method mentioned here to get uploaded video: How do I get a list of uploaded videos for a certain channel with the new YouTube Data API (V3)?
But for curated channels, even this method does not work, the playlist given in channel query result is always empty:
Request
GET https://www.googleapis.com/youtube/v3/channels?part=id%2CcontentDetails%2Csnippet&id=UCEgdi0XIXXZ-qJOFPf4JSKw&key={YOUR_API_KEY}
Authorization: Bearer ya29.dwCMU6xpf5N9AxwAAABgIM94lgv7jGHw0h0oEjs6uZUdPFO28CDYhbvgXdKTjw
X-JavaScript-User-Agent: Google APIs Explorer
Response
200 OK
- Show headers -
{
"kind": "youtube#channelListResponse",
"etag": "\"WFPuK6TsnblcGPcnMex79s42ynQ/qpdedwjxXQ-COrk0dODO-8DTAx0\"",
"pageInfo": {
"totalResults": 1,
"resultsPerPage": 1
},
"items": [
{
"kind": "youtube#channel",
"etag": "\"WFPuK6TsnblcGPcnMex79s42ynQ/TP96YXZ0G4VPdQ7fd2IYgW79rW0\"",
"id": "UCEgdi0XIXXZ-qJOFPf4JSKw",
"snippet": {
"title": "Sports",
"description": "Sport is all forms of usually competitive physical activity which, through casual or organised participation, aim to use, maintain or improve physical ability and skills while providing entertainment to participants, and in some cases, spectators. Hundreds of sports exist, from those requiring only two participants, through to those with hundreds of simultaneous participants, either in teams or competing as individuals. Sport is generally recognised as activities which are based in physical athleticism or physical dexterity, with the largest major competitions such as the Olympic Games admitting only sports meeting this definition, and other organisations such as the Council of Europe using definitions precluding activities without a physical element from classification as sports. However, a number of competitive, but non-physical, activities claim recognition as mind sports.\nThis channel was generated automatically by YouTube's video discovery system.",
"publishedAt": "2013-12-15T20:39:04.000Z",
"thumbnails": {
"default": {
"url": "https://i.ytimg.com/i/Egdi0XIXXZ-qJOFPf4JSKw/1.jpg"
},
"medium": {
"url": "https://i.ytimg.com/i/Egdi0XIXXZ-qJOFPf4JSKw/mq1.jpg"
},
"high": {
"url": "https://i.ytimg.com/i/Egdi0XIXXZ-qJOFPf4JSKw/hq1.jpg"
}
}
},
"contentDetails": {
"relatedPlaylists": {
"likes": "LLEgdi0XIXXZ-qJOFPf4JSKw",
"uploads": "UUEgdi0XIXXZ-qJOFPf4JSKw"
}
}
}
]
}
--
Request
GET https://www.googleapis.com/youtube/v3/playlistItems?part=id%2CcontentDetails%2Csnippet&playlistId=UUEgdi0XIXXZ-qJOFPf4JSKw&key={YOUR_API_KEY}
X-JavaScript-User-Agent: Google APIs Explorer
Response
200 OK
- Show headers -
{
"kind": "youtube#playlistItemListResponse",
"etag": "\"WFPuK6TsnblcGPcnMex79s42ynQ/0ky7gu-r2KEON6-qkmzKhU77B-Q\"",
"pageInfo": {
"totalResults": 0,
"resultsPerPage": 5
},
"items": [
]
}
It seems to me this is a dead end now, so is there any way to get videos from this kind of curated channels?
If you've already got the channel ID of the curated channel, you can just use the search endpoint to get the videos; for example, this API call will receive the 50 most recent videos added to YouTube's sports channel:
https://www.googleapis.com/youtube/v3/search?part=snippet&channelId=UCEgdi0XIXXZ-qJOFPf4JSKw&maxResults=50&order=date&key={YOUR_API_KEY}

Resources