How do I get localised titles and descriptions for automatically generated channels using Youtube API v3? - youtube

I have an application using the v3 YouTube API that lets the use browse videos via the guide API, drilling down from guide categories to channels to videos.
I would like to provide localised results, but get English text in places where I would expect local descriptions. I realise that I can't expect channels belonging to users to be localised, but some of the results appear to be automatically generated channels that would appear translated on the web.
I can get easily get a list of guide categories in e.g. Spanish with a call to youtube.guideCategories.list(part=snippet, hl=es-ES, regionCode=ES):
{
"kind": "youtube#guideCategoryListResponse",
"etag": "\"MmqJLb8ZBOWRQIsg7xej7lrKLMI/RxpLDjICTxI6pEJgKxa1GihOABg\"",
"items": [
{
"kind": "youtube#guideCategory",
"etag": "\"MmqJLb8ZBOWRQIsg7xej7lrKLMI/fnL4T7wf3HKS8VCeb2Mui5q9zeM\"",
"id": "GCQmVzdCBvZiBZb3VUdWJl",
"snippet": {
"channelId": "UCBR8-60-B28hp2BmDPdntcQ",
"title": "Best of YouTube"
}
},
...
{
"kind": "youtube#guideCategory",
"etag": "\"MmqJLb8ZBOWRQIsg7xej7lrKLMI/a2ukJS2cvl7NN20p8C2B9uYePoM\"",
"id": "GCTXVzaWM",
"snippet": {
"channelId": "UCBR8-60-B28hp2BmDPdntcQ",
"title": "Música"
}
},
...
}
}
Apart from a few results like "Best of YouTube", this returns localised guide category titles as I'd expect. The problem comes when I want to drill down into one of these categories.
For example, if I want to get channels in the "Best of YouTube" category, I make a call to youtube.channels.list(part=snippet, categoryId=GCQmVzdCBvZiBZb3VUdWJl):
{
"kind": "youtube#channelListResponse",
"etag": "\"MmqJLb8ZBOWRQIsg7xej7lrKLMI/o8HbT_CvdwGx45Gqb3VT3jnxz8Y\"",
"nextPageToken": "CAUQAA",
"pageInfo": {
"totalResults": 9,
"resultsPerPage": 5
},
"items": [
{
"kind": "youtube#channel",
"etag": "\"MmqJLb8ZBOWRQIsg7xej7lrKLMI/3COvNpjUozOrHwTDRG2SKLHlbDs\"",
"id": "UCEgdi0XIXXZ-qJOFPf4JSKw",
"snippet": {
"title": "Sports",
"description": "Sport is all forms of usually competitive physical activity which, ....\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"
}
}
}
},
...
}
}
As you can see, this automatically generated channel comes back with an English language title and description. This API isn't documented to take an hl parameter to set the desired language, and doesn't behave any differently if I call it with that parameter anyway. I also tried setting the Accept-Language HTTP request header without any luck.
If I browse to this particular automatically generated channel on the YouTube website at https://www.youtube.com/channel/UCEgdi0XIXXZ-qJOFPf4JSKw and change the website language to Spanish I see the localised title "Deportes" and corresponding description, so is there some way to get this same information via the API?

Internationalization in the Data API v3 is something YT started supporting recently, and it's limited now. But there is a work going on to bring this support to the all functionalities in the API really soon.

Since I posted the question, it looks like the YouTube channels.list call has gained an hl parameter, making it possible to retrieve localised results.
So for example, I can retrieve the Spanish localised version of the "Best of YouTube" category with a call to youtube.channels.list(part=snippet, categoryId=GCQmVzdCBvZiBZb3VUdWJl, hl=es-ES):
{
"kind": "youtube#channelListResponse",
"etag": "\"0KG1mRN7bm3nResDPKHQZpg5-do/5ZMIP3f0vZw8CYq69TcuOdye2ZQ\"",
"nextPageToken": "CAUQAA",
"pageInfo": {
"totalResults": 10,
"resultsPerPage": 5
},
"items": [
...
{
"kind": "youtube#channel",
"etag": "\"0KG1mRN7bm3nResDPKHQZpg5-do/kLIkkfyIIZLFzhOb7gB4CIPzKJQ\"",
"id": "UCEgdi0XIXXZ-qJOFPf4JSKw",
"snippet": {
"title": "#Sports",
"description": "Sport or sports are 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. Usually the contest or game is between two sides, each attempting to exceed the other. Some sports allow a tie game; others provide tie-breaking methods, to ensure one winner and one loser. A number of such two-sided contests may be arranged in a tournament producing a champion. Many sports leagues make an annual champion by arranging games in a regular sports season, followed in some cases by playoffs. Hundreds of sports exist, from those between single contestants, through to those with hundreds of simultaneous participants, either in teams or competing as individuals. In certain sports such as racing, many contestants may compete, each against all w...\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"
}
},
"localized": {
"title": "#Deportes",
"description": "El deporte es una actividad física reglamentada, normalmente de carácter competitivo, que puede mejorar la condición física y ocasionalmente psíquica de quien lo practica, y tiene propiedades que lo diferencian del juego.\nLa RAE, en su Diccionario de la lengua española, define deporte como una «actividad física, ejercida como juego o competición, cuya práctica supone entrenamiento y sujeción a normas»; también, en una segunda acepción, más amplia, como «recreación, pasatiempo, placer, diversión o ejercicio físico, por lo común al aire libre». Por otra parte, la Carta Europea del deporte lo define como: «Todas las formas de actividades físicas que mediante una participación organizada o no, tienen como objetivo la expresión o la mejora de la condición física y psíquica, el desarrollo de las relaciones sociales o la obtención de resultados en competición de todos los niveles».\nInstitucionalmente, para...\nEl sistema de detección de vídeos de YouTube ha generado este canal automáticamente."
}
}
},
...
}
}
The localised title and description appear under a new localized attribute on the channel object.

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

YouTube API to get videos from an account

There is an answer that describes how to fetch all videos from a YouTube channel here. However, in many cases, the parent account is not a channel per se, but something similar (like this is a channel, as evidenced by the "channel" word in the URL, while this one is not, since it has a keyword "c" in the URL, and not "channel"). I can still get playlists from it, and get all videos from individual playlist in that WWE account, but there are many videos in that account that are not part of any playlist listed in the account, like this).
Question - Is there a way to get all videos from an account, not just a channel or a playlist? Or is there any way to get default playlist/channel from an account where all unlisted videos such as above can be found?
Edit (15/03/2022):
I've found that the video_id = eJjbnFZ6yA8 is on the "uploads" playlist and it's in the position # 7765.
You can try to get the position in the given playlist by making this query:
https://content-youtube.googleapis.com/youtube/v3/playlistItems?maxResults=50&playlistId=<UPLOADS_PLAYLIST_ID>&videoId=<VIDEO_ID_YOU_WANT_TO_GET>&part=id,snippet,contentDetails,status&key=[YOUR_API_KEY]
These are the results of the video_id = eJjbnFZ6yA8:
URL:
https://content-youtube.googleapis.com/youtube/v3/playlistItems?maxResults=50&playlistId=UUJ5v_MCY6GNUBTO8-D3XoAg&videoId=eJjbnFZ6yA8&key=[YOUR_API_KEY]&part=id,snippet,contentDetails,status
Response:
{
"kind": "youtube#playlistItemListResponse",
"etag": "SyO-_mevTIc8xX7G8QA0JKcgwTE",
"items": [
{
"kind": "youtube#playlistItem",
"etag": "70IgC85z_68I9jCkp4Jwuwo_pO8",
"id": "VVVKNXZfTUNZNkdOVUJUTzgtRDNYb0FnLmVKamJuRlo2eUE4",
"snippet": {
"publishedAt": "2020-12-27T21:05:54Z",
"channelId": "UCJ5v_MCY6GNUBTO8-D3XoAg",
"title": "FULL MATCH - The Rock vs. Mankind – WWE Championship Match: Raw, Jan. 4, 1999",
"description": "Mankind looks to make his dream come true when he challenges The Rock for the WWE Championship on the first Raw of 1999: Courtesy of WWE Network.\nWWE Network | Subscribe now: http://wwe.yt/wwenetwork\r\n---------------------------------------------------------------------\r\nFollow WWE on YouTube for more exciting action!\r\n---------------------------------------------------------------------\r\nSubscribe to WWE on YouTube: http://wwe.yt/\r\nCheck out WWE.com for news and updates: http://goo[.]gl/akf0J4\r\nWatch WWE on Sony in India: http://www.wwe.com/SonySportsNetwork\r\nFind the latest Superstar gear at WWEShop: http://shop.wwe.com\r\n---------------------------------------------\r\nCheck out our other channels!\r\n---------------------------------------------\r\nThe Bella Twins: https://www.youtube.com/thebellatwins\r\nUpUpDownDown: https://www.youtube.com/upupdowndown\r\nWWEMusic: https://www.youtube.com/wwemusic\r\nTotal Divas: https://www.youtube.com/wwetotaldivas\r\n------------------------------------\r\nWWE on Social Media\r\n------------------------------------\r\nTwitter: https://twitter.com/wwe\r\nFacebook: https://www.facebook.com/wwe\r\nInstagram: https://www.instagram.com/wwe/\r\nReddit: https://www.reddit.com/user/RealWWE\r\nGiphy: https://giphy.com/wwe\r\n------------------------------------\r\nWWE Podcasts\r\n------------------------------------\r\nAfter the Bell with Corey Graves: https://wwe.com/afterthebell\r\nThe New Day: Feel the Power: https://wwe.com/feelthepower\r\nUncool with Alexa Bliss: https://wwe.com/uncoolwithalexa",
"thumbnails": {
"default": {
"url": "https://i.ytimg.com/vi/eJjbnFZ6yA8/default.jpg",
"width": 120,
"height": 90
},
"medium": {
"url": "https://i.ytimg.com/vi/eJjbnFZ6yA8/mqdefault.jpg",
"width": 320,
"height": 180
},
"high": {
"url": "https://i.ytimg.com/vi/eJjbnFZ6yA8/hqdefault.jpg",
"width": 480,
"height": 360
},
"standard": {
"url": "https://i.ytimg.com/vi/eJjbnFZ6yA8/sddefault.jpg",
"width": 640,
"height": 480
},
"maxres": {
"url": "https://i.ytimg.com/vi/eJjbnFZ6yA8/maxresdefault.jpg",
"width": 1280,
"height": 720
}
},
"channelTitle": "WWE",
"playlistId": "UUJ5v_MCY6GNUBTO8-D3XoAg",
"position": 7765,
"resourceId": {
"kind": "youtube#video",
"videoId": "eJjbnFZ6yA8"
},
"videoOwnerChannelTitle": "WWE",
"videoOwnerChannelId": "UCJ5v_MCY6GNUBTO8-D3XoAg"
},
"contentDetails": {
"videoId": "eJjbnFZ6yA8",
"videoPublishedAt": "2021-01-04T16:00:08Z"
},
"status": {
"privacyStatus": "public"
}
}
],
"pageInfo": {
"totalResults": 1,
"resultsPerPage": 50
}
}
Initial response (17/02/2022):
That's a odd result, IMHO. You can follow any of these steps:
Get all playlists from a given channel and loop every video in every playlist obtained and compare to the video_id you want to check if it belongs to any playlist found.
If the video is not found in any playlist, probably is due the video itself does not belong to any created playlist, but, rather, to the "Uploads" playlist of the owner channel.
For check the last point I mentioned in my comment and in this answer, you can follow these steps:
Replace the second character of the channel_id from "C" to "U". Example: channel_id: UCJ5v_MCY6GNUBTO8-D3XoAg - once modified, the result is: UUJ5v_MCY6GNUBTO8-D3XoAg = this is the "Upload" playlist_id of the channel UCJ5v_MCY6GNUBTO8-D3XoAg.
With the upload playlist_id, paste it in this URL: https://www.youtube.com/playlist?list=<UPLOAD_PLAYLIST_ID_OF_THE_CHANNEL>
Result:
https://www.youtube.com/playlist?list=UUJ5v_MCY6GNUBTO8-D3XoAg
Then, you can yield the default "uploads" playlist of the given channel and their videos in it.
N.B that some videos (including probably the video_id you supplied) might not appear in any playlist, for example, when entering to the "upload playlist" sample (i.e. https://www.youtube.com/playlist?list=UUJ5v_MCY6GNUBTO8-D3XoAg), you might get this message above the playlist itself:
Unavailable videos are hidden.
In this case, might be worth it use the YouTube Data API to query the videos in UUJ5v_MCY6GNUBTO8-D3XoAg playlist or double-check if the video in subject in you region is available - in my case, Colombia, I got the message mentioned above, but, probably this wont happen in the US or UK.

No videos in the mostPopular chart for certain video categories

I'm trying to get a list of the most popular videos for certain video categories, however some categories return an empty list of videos despite the response being successful.
For example, the News & Politics category (ID 25):
I get the same response when making this request from my app. The category ID is valid and correct (as obtained from /youtube/v3/videoCategories). Changing the regionCode doesn't make a difference.
It's really important for the functionality of my app that a list of popular/recent/noteworthy videos for particular categories are shown. If there's no way to get the above request to return some videos, is there some kind of workaround that would return appropriate videos for the troublesome categories?
This looks like a bug to me
I tested it in the apis-explorer
Testing request 1:
Without category. test here scroll down there are some with nr 25
Request
GET https://www.googleapis.com/youtube/v3/videos?part=snippet&chart=mostPopular&maxResults=50&regionCode=us&fields=items%2Fsnippet%2FcategoryId&key={YOUR_API_KEY}
Response
{
"kind": "youtube#videoListResponse",
"etag": "\"RmznBCICv9YtgWaaa_nWDIH1_GM/ewwRz0VbTYpp2EGbOkvZ5M_1mbo\"",
"pageInfo": {
"totalResults": 0,
"resultsPerPage": 50
},
"items": [
"snippet": {
"categoryId": "25"
}
......
]
}
but as soon as you add the catagori id it returns 0
Test 2 fun results
A fun thing i found in my testing is if i add a category id of 10 link
GET https://www.googleapis.com/youtube/v3/videos?part=snippet&chart=mostPopular&maxResults=50&regionCode=us&videoCategoryId=10&fields=items%2Fsnippet%2FcategoryId&key={YOUR_API_KEY}
it returns others as well.
{
"items": [
{
"snippet": {
"categoryId": "24"
}
},
{
"snippet": {
"categoryId": "10"
}
},
{
"snippet": {
"categoryId": "10"
}
I would submit a bug report. issue forum

API endpoint /activities doesn't return historical activities (only very recent ones are accessible)

Here is the oldest page I can scroll down for activities.list API for TEDx Talks channel
GET https://www.googleapis.com/youtube/v3/activities?part=snippet&channelId=UCsT0YIqwnpJCM-mx7-gSA4Q&maxResults=50&pageToken=CPoBEAA&fields=items(snippet(publishedAt%2Ctitle))%2CnextPageToken%2CprevPageToken&key={YOUR_API_KEY}
and response is
{
"prevPageToken": "CPoBEAE",
"items": [
{
"snippet": {
"publishedAt": "2017-11-21T18:30:36.000Z",
"title": "You Are Not Who They Think You Are | Vinny McCoy | TEDxDrogheda"
}
},
{
"snippet": {
"publishedAt": "2017-11-21T18:27:43.000Z",
"title": "What does it mean to be authentic? | Sarah Archer | TEDxDrogheda"
}
},
{
"snippet": {
"publishedAt": "2017-11-21T18:27:33.000Z",
"title": "Moments in Jazz | Jazz Quartet of the Conservatory of the Polyphonic Choir of Patras | TEDxPatras"
}
},
{
"snippet": {
"publishedAt": "2017-11-20T20:14:23.000Z",
"title": "Moments in Jazz | Jazz Quartet of the Conservatory of the Polyphonic Choir of Patras | TEDxPatras"
}
},
{
"snippet": {
"publishedAt": "2017-11-21T18:22:57.000Z",
"title": "Adriano Teixeira | Adriano Teixeira | TEDxPassoFundo"
}
},
{
"snippet": {
"publishedAt": "2017-11-21T18:21:50.000Z",
"title": "Eargasm - Beat Box Act by Ivory Parker aka neXor | Ivory Parker | TEDxDonauinsel"
}
}
]
}
You can see that there is no nextPageToken that means you can't scroll further, and the oldest activity has
"publishedAt": "2017-11-21T18:21:50.000Z"
Meanwhile, there is at least this video
https://www.youtube.com/results?search_query=xzA-QZ0yqJg
published 2017-10-24.
UPD: Reported issue case was fixed on Youtube API side.
You are interrogating activities which is returning a list of "kind": "youtube#activity" and the item you are providing as an example is listed as "kind": "youtube#video". If you would use the video endpoint rather than activities you will find that item too.
UPDATE
It looks like there is a limit of historycal activities that are served by the call.
I succeed browsing the activities by specifying publishedBefore parameter. The pagination will bring you a lot further.
Eg.
GET https://www.googleapis.com/youtube/v3/activities?part=snippet%2CcontentDetails&channelId=UCsT0YIqwnpJCM-mx7-gSA4Q&maxResults=50&pageToken=CGQQAA&publishedBefore=2017-10-25T18%3A21%3A50.000Z&fields=items(snippet(publishedAt%2Ctitle))%2CnextPageToken&key={YOUR_API_KEY}
Date used can be, obviously, something in the future to cover everything.

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"
}
}
]
}

Resources