Youtube video id (or URL) to "user" and "channel" - youtube

Given a URL or ID of a Youtube video, is it possible to get the (1) name of the "user" who had uploaded it and (2) channel that it belongs to? If so, what is the API request?
So, for example: lets' say I have a video ID: "VulCl5QfewE" corresponding to the video at: https://www.youtube.com/watch?v=VulCl5QfewE
I then want to extract the name of the user, which is: "TheYoungTurks" and the URL of the user is:
https://www.youtube.com/user/TheYoungTurks
I also want to be able to extract the name of the channel, which is: "UC1yBKRuGpC1tSM73A0ZjYjQ" and the URL of the channel is:
https://www.youtube.com/channel/UC1yBKRuGpC1tSM73A0ZjYjQ
Finally, (as a "side, ancillary question") I am a bit confused what is the difference between a "channel" and a "user". Can a user have multiple channels? I did read the link here: https://www.reddit.com/r/youtube/comments/2vsyit/whats_the_difference_between_user_and_channel/ but I am trying to understand the use case behind it.
Cheers

If you want to retrieve the channel informations from a videoId, you need to use the ressource videos.list with the parameters:
part: snippet
id: "VulCl5QfewE" //for example
GET https://www.googleapis.com/youtube/v3/videos?part=snippet&id=VulCl5QfewE&key={YOUR_API_KEY}
The result show you the channelID of the user:
"items": [
{
"kind": "youtube#video",
"etag": "\"iDqJ1j7zKs4x3o3ZsFlBOwgWAHU/IcNtD4uunskZTQuIeM0YQRcc5HY\"",
"id": "VulCl5QfewE",
"snippet": {
"publishedAt": "2015-08-05T01:11:24.000Z",
"channelId": "UC1yBKRuGpC1tSM73A0ZjYjQ",
Then use this information to get the name of the channel with the ressource channel.list
part: snippet
id: UC1yBKRuGpC1tSM73A0ZjYjQ
GET https://www.googleapis.com/youtube/v3/channels?part=snippet&id=UC1yBKRuGpC1tSM73A0ZjYjQ&key={YOUR_API_KEY}
Part of the result:
"snippet": {
"title": "The Young Turks",
"description": "The Largest Online News Show in the World. Hosted by Cenk Uygur & Ana Kasparian. LIVE weekdays 6-8pm ET. \n\nYoung Turk (n), 1. Young progressive or insurgent member of an institution, movement, or political party. 2. Young person who rebels against authority or societal expectations. (American Heritage Dictionary)\n\nThe Young Turks were the first original talk show on Sirius satellite radio and the first live, daily webcast on the internet. But that is not the revolution.\n\nWe are a rare show that combines all of the news that people care about in one place. We are not afraid to talk about politics and entertainment and sports and pop culture. But that is not the revolution either. \n\nGet The Young Turks\u200b Mobile App Today! \n\nDownload the iOS version here: https://itunes.apple.com/us/app/the-young-turks/id412793195? \n\nDownload the Android version here: https://play.google.com/store/apps/details?id=com.tyt",
"publishedAt": "2005-12-21T20:46:51.000Z",
Finally, (as a "side, ancillary question") I am a bit confused what is
the difference between a "channel" and a "user". Can a user have
multiple channels? I did read the link here:
https://www.reddit.com/r/youtube/comments/2vsyit/whats_the_difference_between_user_and_channel/
but I am trying to understand the use case behind it.
There is a link with Google+ account, check https://productforums.google.com/forum/#!topic/youtube/3MsBApaK2Hw

Related

How can I solve Video Rating Disabled?

I'm doing a project using the YouTube Data API's Videos.rate endpoint.
And I got some problems: some particular minor channels (e.g. my client's channel) are sending error messages:
{
"error": {
"code": 403,
"message": "The owner of the video that you are trying to rate has disabled ratings for that video.",
"errors": [
{
"message": "The owner of the video that you are trying to rate has disabled ratings for that video.",
"domain": "youtube.video",
"reason": "videoRatingDisabled",
"location": "id",
"locationType": "parameter"
}
]
}
My boss wants to help them to solve that problem, but I don't know how to solve this at all. There is no problem with other major channels with 1M+ subscriptions.
I did my best to google this problem, yet couldn't find good results until now.
Before rating the video, check if the vide has enabled the rating.
I can't test right now, but, and idea could be:
Use getRating and check the items[].rating value - if the result is none or unspecified, then, you have to handle your logic for make them know that this video can't be rated - due its owner disabled rating their video.
The message you show in your question says that you cannot rate that video because the owner doesn't allow it. YouTube Data API wont bypass such restriction and there's not much that can be done further.
Ask your boss (or the owner of the video) about allow rating their video(s) and then verify if the video can be rated, if so, try again rate the video.

YouTube Data API v3 - Problem with categoryId from category list

If I upload a video which has CategoryId 34 (Comedy/Komödie), the API tells me the CategoryId isn't available/supported.
But I got the Categories from YouTube, saved the List in a DB with the following call:
https://developers.google.com/youtube/v3/docs/videoCategories/list?apix_params=%7B%22part%22%3A%22snippet%22%2C%22hl%22%3A%22de_DE%22%2C%22regionCode%22%3A%22DE%22%7D
and this category exists.
So with every "failed upload" my Quota raises. Unfortunately I can upload only 6 videos a day.
Any suggestions?
I checked the Categories, still up-to-date
According to the URL of the request you provided in your question, you're using de_DE as regionCode.
If so, you need to use the id 23 instead - which corresponds to Komödie.
See:
{
"kind": "youtube#videoCategory",
"etag": "\"0UM_wBUsFuT6ekiIlwaHvyqc80M/l3o_qqirQJQvOVhrSz9qa3x9Nxo\"",
"id": "23",
"snippet": {
"channelId": "UCBR8-60-B28hp2BmDPdntcQ",
"title": "Komödie",
"assignable": true
}
}
You can test the results in these demos:
Results of videoCategories.list from Germany "de_DE" in YouTube Official Documentation - "try-it" feature.
Results of videoCategories.list from Germany "de_DE" in Google API Explorer demo.
If you're still sure there's a problem with YouTube Data API, my advice is search whether your problem is already reported on Issue Tracker or report the problem there.

How to get region of YouTube channel for a user?

My web app generates video and uploads it to users channel using YouTube Data API v.3.
After a user authorizes my app via OAuth, a form asks for video title, description, tags and video category.
Available categories list depends on user/channel region, as far as I know, so I must offer a relevant individual list of categories to pick from. That means a new API request for every session. However the list could easily be cached my server side to reduce the number of YouTube API requests.
If only region code would be available after authorization.
How can I learn the region code of the YouTube channel a user selected when granting youtube.upload permission to my app?
You have to make a request about the channel's info.
Like:
https://www.googleapis.com/youtube/v3/channels?part=snippet%2CcontentDetails&id=<CHANNEL_ID>&fields=items(brandingSettings%2Fchannel%2Fcountry%2Csnippet(country%2Cdescription)%2CtopicDetails)&key={YOUR_API_KEY}
and get the country result.
Example: here I'm requesting the country of the channel Musicoterapia - channel_id: UCf4iMeUCDs0NFkJI03aJSbQ:
https://www.googleapis.com/youtube/v3/channels?part=snippet%2CcontentDetails&id=UCf4iMeUCDs0NFkJI03aJSbQ&fields=items(brandingSettings%2Fchannel%2Fcountry%2Csnippet(country%2Cdescription)%2CtopicDetails)&key={YOUR_API_KEY}
The results are:
{
"items": [
{
"snippet": {
"description": "Bienvenidos al canal de musicoterapia, en nuestro canal podrás encontrar música relajante para dormir, meditación, yoga, zen, spa, estudiar y concentrarse, ondas cerebrales, cuencos tibetanos, música chamánica, y mucho más.\n\nNo olvides suscribirte para estar al día de nuevas publicaciones.",
"country": "ES"
}
}
]
}
You can test this request in the Google API Explorer.
Notice here that the country code is ES.
Another channel example is: Justin Johnson - channel_id: UCzH2vVrSpjwHNM0U3jJM0lQ
{
"items": [
{
"snippet": {
"description": "Justin Johnson : Official YouTube Channel\n\nLive Concert Footage, Interviews, Press, and Instrument Showcases. How-To Workshops on Guitar, Lap Steel, Slide Guitar, and Roots Instruments. \n\nBooking & Media Inquiries: Contact#JustinJohnsonLive.com",
"country": "US"
}
}
]
}
You can test this request in the YouTube official documentation - channel.list demo.
Notice here that the country code is US.
Once you have the country code, you can proceed as user Mak suggested in his answer.
The only workaround is using guideCategories.
You can list guideCategories by region.
Then in your channels->list call you can plug that category ids.
Find country of channel in youtube api v3

What is the maximum size/length of IDs, especially for comment IDs

I'm trying to find the maximum size of the different IDs of the YouTube API.
Can someone tell me where can I found this or what is the maximum number of characters of:
- Comments IDs
- Channels IDs
- Playlists IDs
- Subscriptions IDs
Thank you!
Dan
You can get the Comments ID from the JSON response in the Resource representation ("id": string) section of the documentation.
See the JSON structure of a comments resource
{
"kind": "youtube#comment",
"etag": etag,
"id": string,
"snippet": {
"authorDisplayName": string,
"authorProfileImageUrl": string,
"authorChannelUrl": string,
"authorChannelId": {
"value": string
},
"channelId": string,
"videoId": string,
"textDisplay": string,
"textOriginal": string,
"parentId": string,
"canRate": boolean,
"viewerRating": string,
"likeCount": unsigned integer,
"moderationStatus": string,
"publishedAt": datetime,
"updatedAt": datetime
}
}
Same with Channels ID, Playlist ID, Subscription ID.
Unfortunately, coming from the YouTube developer that they do not guarantee about the length of each specific ID.
Here is a StackExchange post as a reference.
It was mentioned that the word is coming from a YouTube developer, here is the link from Google Groups Forum to justify.
Hello Hans,
I don't see anywhere in the documentation where we officially commit
to a standard length of 11 characters for YouTube video ids. It's one
of those things where we have a current implementation, and it may
stay that way indefinitely. But we're not offering any official
commitment to that, so proceed at your own risk.
A better approach, though one that's more involved, would be to take
each video id and make a request to the YouTube API to see if it's
valid. E.g., make an HTTP GET to
http://gdata.youtube.com/feeds/api/videos/VIDEO_ID
and see if you get back a HTTP 200 response. Of course, if you take
that approach, videos that have been removed from YouTube will come
back as invalid (which may or may not be what you want) and videos
that have been very recently uploaded to YouTube might also come back
as invalid.
Cheers,
-Jeff Posnick, YouTube API Team

YouTube API - No channel branding settings returned for queries by username

When using the YouTube API v3 to query a channel's branding settings, why are they returned for queries by channel ID, but not for queries by username? The API doesn't return branding settings for channel list queries by username.
If you query for a channel's branding settings by channel ID (e.g., id=UC8-Th83bH_thdKZDJCrn88g), you are returned a complete set of branding settings:
Google API Explorer: https://developers.google.com/youtube/v3/docs/channels/list
Request
GET https://www.googleapis.com/youtube/v3/channels?part=brandingSettings&id=UC8-Th83bH_thdKZDJCrn88g&key={YOUR_API_KEY}
Response
{
// ... snip ...
"items": [
{
"kind": "youtube#channel",
"etag": "\"...\"",
"id": "UC8-Th83bH_thdKZDJCrn88g",
"brandingSettings": {
"channel": {
"title": "The Tonight Show Starring Jimmy Fallon",
"description": "Watch The Tonight Show Starring Jimmy Fallon Weeknights 11:35/10:35c\n\nThe Tonight Show Starring Jimmy Fallon features hilarious highlights from the show including: comedy sketches, music parodies, celebrity interviews, ridiculous games, and, of course, Jimmy's Thank You Notes and hashtags! You'll also find behind the scenes videos and other great web exclusives.",
// all the branding settings are here
}
}
}]
}
If, on the other hand, you send a channel list query for a username (e.g., forUsername=latenight), you get no branding settings at all. The branding settings aren't returned or populated.
Request
GET https://www.googleapis.com/youtube/v3/channels?part=brandingSettings&forUsername=latenight&key={YOUR_API_KEY}
Response
{
// ... snip ...
"items": [
{
"kind": "youtube#channel",
"etag": "\"...\"",
"id": "UC8-Th83bH_thdKZDJCrn88g"
}]
}
I may be wrong, but I believe that, in v3 of the APIs, Channel IDs are the only way to get a full response, as the concept of a "username" doesn't really exist in the same way anymore. That is, newly created YouTube channels are linked to a G+ profile and can have a display name, but there isn't really any YouTube username anymore associated with such a channel.
Because usernames used to exist, though, and many channels are still known by them, the "forUsername" parameter is there to provide you the associated channelID and then issue the request for the branding settings with that.
Now, having said that, it's clear that the language on the API explorer page doesn't reflect that, and perhaps therein lies the problem; I'm taking my inferences from this documentation:
https://developers.google.com/youtube/v3/guides/working_with_channel_ids#v3
and from this bug report:
https://code.google.com/p/gdata-issues/issues/detail?id=4821&q=forUsername&colspec=API%20ID%20Type%20Status%20Priority%20Stars%20Summary
But it's always possible, too, that I'm reading incorrectly and you're actually seeing a new bug. The only way to know for sure would be to file it (or perhaps someone on the team could comment here)?

Resources