I am trying to use the YouTube Data API to fetch channel data for particular channels. According to the documentation, I can use list (by channel ID) or list (by YouTube username)
Search by channel ID
https://youtube.googleapis.com/youtube/v3/channels?part=snippet&id={ChannelID}&key={APIKey}
// Get channel by YouTube username
https://youtube.googleapis.com/youtube/v3/channels?part=snippet&forUsername={Username}&key={APIKey}
The channel ID can be retrieved by going to YouTube in a browser and search for the channel by name and then when you select the channel; the channel ID is part of the URL like this:
https://www.youtube.com/channel/UCbTw29mcP12YlTt1EpUaVJw.
This particular channel is for Sean Allen and his YouTube URL is:
https://www.youtube.com/SeanAllen.
I would have thought that the YouTube username would be SeanAllen, but it is not because, when I use that term in the API request, I get 0 results.
However, in my own case, my channel ID is UCOWdR4sFkmolWkU2fg669Gg and the search by channel ID works to fetch my channel data. My YouTube URL is:
https://wwww.youtube.com/StewartLynch
and, if I use StewartLynch as the username, I can use that 2nd API request to fetch the same data.
So, my question is, how does one find the correct YouTube username for a channel? Apparently it is not what is used in the channel URL.
The issue you're raising is recurrent time and again on Stack Overflow. I myself already tackled all faces of it (just issue either of the following SO search terms: user:8327971 custom URL or user:8327971 forUsername).
The short story is as follows: don't rely much on YouTube user names.
User names are a legacy feature of the API v3: not every channel has one attached and no channel is required to have one attached. (See this official statement from Google staff from 2013-07-11.)
Here is what YouTube Data API returns for the two names -- SeanAllen and StewartLynch -- of your post:
$ python3 youtube-search.py --custom-url SeanAllen
UCbTw29mcP12YlTt1EpUaVJw
$ python3 youtube-search.py --user-name SeanAllen
UCRGhxM6u14Uv309cC0ywEqA
$ python3 youtube-search.py --custom-url StewartLynch
UCOWdR4sFkmolWkU2fg669Gg
$ python3 youtube-search.py --user-name StewartLynch
UCOWdR4sFkmolWkU2fg669Gg
As you can see, StewartLynch is both the custom URL and the user name of the channel of which ID is UCOWdR4sFkmolWkU2fg669Gg.
But, in case of SeanAllen, things are not that simple since there's a channel -- UCbTw29mcP12YlTt1EpUaVJw -- that has its custom URL set to this name; and, at the same time, there's a different channel -- UCRGhxM6u14Uv309cC0ywEqA -- that has its attached user name set to the this very same name.
This situation is very much perennial with YouTube: many channels out there have in common this property.
The final note, which closes your question:
how does one find the correct YouTube UserName for a channel?
The Channels.list API endpoint queried with the request parameter forUsername does return the correct user name of a given channel (if the respective channel has attached an user name).
The ambiguity stems from the fact that URLs of form:
https://www.youtube.com/NAME
may well represent either a channel of which user name is NAME or a channel of which custom URL is NAME. The two cases can be set apart only by the (not-completely reliable) procedure of searching for custom URLs (which is implemented already by the script youtube-search.py).
Above I make use of my public (MIT licensed) Python 3 script youtube-search.py; this script is able to search the API for custom URLs and respectively query the API for user names.
Note that youtube-search.py requires a valid API key to be passed to it as argument of the command line option --app-key or, otherwise, passed on as the environment variable YOUTUBE_DATA_APP_KEY. (Use the command line option --help for brief helping info.)
Related
I'm trying to get channels info with ChannelsList. This endpoint has a parameter the name is: forUsername but it does not work for this page: https://www.youtube.com/c/FolkartTr
This is my query and it returns empty data:
Somehow, I got this channelID in the page source and its: "channelId":"[UCnS--2e1yzQCm5r4ClrMJBg]".
When I try to query with this ID it's okay and returns with correct data.
and this is its payload: http://jsonblob.com/941253671862419456
How will I be able to reach this channel info using a username? I got a few links with usernames and I want to get their info with their username. I don't have any chance to get their channelID's for all.
Thanks for your help.
If I understood correctly, your problem is that you can't do anything from such a username with the Channels: list of the YouTube Data API v3. If you're just looking for the channel id linked to this username then because as YouTube Data API v3 doesn't work for this, I would recommend you to use my open-source YouTube operational API, indeed by requesting https://yt.lemnoslife.com/channels?part=snippet&forUsername=FolkartTr you'll receive a JSON with id equals to the channel id linked to the provided forUsername value.
If you have any question don't hesitate to comment or come to the Discord support.
Notice that the channel title and the channel customUrl might be different.
In your example - http://jsonblob.com/941253671862419456 -, the channel title is Folkart, but its customUrl - which is the value you get when view on YouTube - is: folkarttr.
Note the difference in both case-sensitive and additional letters.
For these reasons, you should not based your channel search by name, but, rather, by its channel_id.
If you really need to search by userName, the answer from Benjamin Loison can solve your requirement.
See if you can find a ticket on Issue Tracker or post your issue there too. Then, you might get some official answer.
So, I have a request that should list my subscribers who do not have the private subscriptions option enable. My request is:
response = youtube.subscriptions().list(
part="snippet",
maxResults=50,
mySubscribers=True
).execute()
However, in items resource, every channel returned is my own channel. My channel name, ID and profile images. Is this the problem with the API or am I making a wrong request?
I also tried using the Try this API option on the documentation, but it also returns the same result.
https://developers.google.com/youtube/v3/docs/subscriptions/list
Thank you for any help you can give
According to the official docs you already quoted, you should have passed to your API call the parameter part as:
part="snippet,subscriberSnippet".
The subscriberSnippet part gives you the needed info:
subscriberSnippet (object)
The subscriberSnippet object contains basic details about the subscriber.
For what concerns the snippet part, the official doc is indeed a bit ambiguous:
snippet (object)
The snippet object contains basic details about the subscription, including its title and the channel that the user subscribed to.
Nevertheless, the info you get from part="snippet" only is correct.
For some reason I can't get any information for some channels via API. For example this channel: http://youtube.com/vithorvascovv and API request
GET https://www.googleapis.com/youtube/v3/channels?part=id&forUsername=vithorvascovv&key={YOUR_API_KEY}
gives me empty response. Why? You can try here with part=id and forUsername=vithorvascovv.
Even if I use search method like this:
GET https://www.googleapis.com/youtube/v3/search?part=id&q=vithorvascovv&type=channel&key={YOUR_API_KEY}
I have empty response but in same time channel can be found by using regular search on Youtube.
One more channel name with the same problem: Nsamurail
It looks like the user "vithorvascovv" merged with another channel. I'm not exactly sure why the username lookup no longer works, but I see that http://youtube.com/vithorvascovv redirects to https://www.youtube.com/channel/UCsLprVocGZ9mUl6SGBZ91Ng. Using part=id and id=UCsLprVocGZ9mUl6SGBZ91Ng, I was able to return the proper results from the API.
For your second question, it looks like user "Nsamurail" changed their username to "xRidan" (http://www.youtube.com/Nsamurail redirects to https://www.youtube.com/user/xRidan). Using part=id and forUsername=xRidan, I was able to return the channel information from the API.
Question : How Can Fetch Playlists From Any Youtube Channel Name/User By Using YOUTUBE DATA API ?
Answer : When You Try To Do This We Always Face A Problem to apply "FILTER" in order to fetch Playlists , here you can use two different filters (forUsername,Id) in two different Youtube channel urls such as :
1. https://www.youtube.com/user/flashbuilding/playlists
Here channel name is : flashbuilding
Required Filter For API is: forUsername
Code Structure :
forUsername:flashbuilding
2. https://www.youtube.com/channel/UCJUmE61LxhbhudzUugHL2wQ/playlists
Here Chanel Name is not clear in this case:-
Required filter for API is : Id
Code Structure :
Id:UCJUmE61LxhbhudzUugHL2wQ
Note : use Id in API Filter section instead of API part Section
Youtube allows a username and channel name. They can be different from each other. The youtube API allows me to search via username but I can't see where or how to search by channel name. It is the channel name that is displayed under the videos.
Anyone shed some light onto how I can search via channel name/title and not username?
Thanks
If the channel search API didn't return a result I call the search API
https://www.googleapis.com/youtube/v3/search?part=snippet&type=channel&maxResults=1&q=(<# potential channel name #>)
So it runs a standard search for entered value "potential channel name". Google docs say the first returned result will be a channel so we only need 1 result which is why we set maxResults=1.
If that returns nothing then I assume channel does not exists and display error to user
This works with me, just change the key with your api-key
url1="[https://www.googleapis.com/youtube/v3/search?part=snippet&type=channel&maxResults=15&q=Inna&key=[YOUR-API-KEY]"
r = requests.get((url1))
print(r.content)
It returns all channels with names that contain the word Inna
Hope this can help you
I am retrieving all of the videos for a given channel by:
'https://gdata.youtube.com/feeds/api/users/{username}/uploads'
When I go to a channel, such as: http://www.youtube.com/channel/UCXIyz409s7bNWVcM-vjfdVA I have the channel ID and I can quite clearly see the videos. Also, if I click on the 'Videos' tab I can see all the videos, but the URL changes to: http://www.youtube.com/user/majesticcasual/videos
I would like to take the channel ID and retrieve the username for the given channel such that I can query YouTube's API for the videos by channel ID. Is this possible?
If you retrieve this feed:
https://gdata.youtube.com/feeds/api/users/[channel_id]/
You'll get a response that includes an <author> element -- the <name> child of that <author> element is the username. It's also repeated in that same feed as <yt:username>.
Of course, that's kind of moot, because you can query by channelID directly:
https://gdata.youtube.com/feeds/api/users/[channel_id]/uploads
is the same feed as if you'd used the username. This works because the channel_id really is just the unique ID of someone's username.
If you want to use v3 of the API (Which is highly encouraged, as it's at production level now), you could use this feed:
GET https://www.googleapis.com/youtube/v3/playlistItems?part=snippet&playlistId=UUXIyz409s7bNWVcM-vjfdVA&key={YOUR_API_KEY}
Note that I've changed the channel id so instead of starting with UC (as all channel ids do), I'm passing in a value that starts with UU ... this is so you get back the uploads feed of the channel (you could also have it start with LL instead to get back the 'likes' feed, for example ... or even do a request to:
GET https://www.googleapis.com/youtube/v3/channels?part=snippet%2CcontentDetails&id=UCXIyz409s7bNWVcM-vjfdVA&key={YOUR_API_KEY}
To retrieve, in the contentDetails parameter, all of the playlists associated with that particular channel.