How do I use Youtube Data API V3 to fetch channel uploads using chanel's username? - youtube-api

I've explored most of this topic using the previous question How do I get a list of uploaded videos for a certain channel with the new YouTube Data API (V3)?, but I wanted some specifics that build upon the answer given.
Is it possible to use the channel's username without calling a search query to get the channel ID? I have an https request that can get a search list shown below, but I'd rather not waste API quotas when I know the exact channel username.
https://www.googleapis.com/youtube/v3/search?q={channel_username}&key={my_api_key}&part=snippet
My hack for this is just take a videoid from the channel and extract a uploader ID from there, but its not elegant and won't work if the upload is removed.
Also, once I've worked my way down to getting the uploads key, how can I get a json that shows all of the uploads and not just a list of 25? If I do have to recursively call pages of uploads, how can I do that?
Thanks.

I think that to get a channel, using the channel's username, the only option is to use the search, and the best strategy to minimize the use of quota is to use a cache, or save the channel ID.
For a full list of videos uploaded, as JSON, you can use contentDetails.relatedPlaylists.uploads (the ID of the playlist that contains the channel's uploaded videos) and retrieve the PlaylistItems, using pages with 50 items per page, and using the nextPageToken value to retrieve each page in the result set.

I've found the answer. The correct way to go about it is to query the site using the search, but directly state the type of list to respond with, in effect searching only channels. This is done by
https://www.googleapis.com/youtube/v3/search?q={search_term}&key={API_key}&type=channel&part=snippet
As you can see the type is channel. By searching with a search term of the exact channel username, you'll get a return list with the first item object as the channel, and you can store the channel ID and upload ID from there.

To update this answer, you need to recognise the "quota limits".
As such, to use the "search?q=[search]" will incur a 100 quota usage.
Better to use "channels?part=id&forUsername={username]" as is only a quota of 1.
Then you can use "channels?part=id,snippet ....... &id={channel_ID]" to grab all your data

Related

Formating the api url to return only the videoId. (And use minimal quota)

So I'm using Home Assistant to launch an automation that retrieves the newest videoId that a channel has uploaded, so I can use my google home to play it(on a Roku TV), works fine, I am working on creating an automation that also does a GET request but for now, I am using the home assistant rest sensor that updates by performing a GET after a set number of seconds, for some reason though there are only 3 sensors polled every minute or so it seems they use around 100-500 quota(hitting my quota of 10,000 after only a few hours or less), I'm not sure if this is a home assistant problem or if I am not using the api correctly(I only need the videoId), ill link my url below:
https://www.googleapis.com/youtube/v3/search?key=API_KEY&part=id&order=date&maxResults=1
Expected 1-3 quota usage per GET, getting 100+ quota usage per GET.
Querying the Search Endpoint is more expensive than querying the PlaylistItems endpoint for the given user's uploads playlist. Depending on usage patterns, the default quotas may put rather tight limits on the number of calls an user is allowed to make on various endpoints of the API.
Adapting my answer to a different question, I suggest you to do the following instead: call PlaylistItems endpoint, passing to it as playlistId parameter the given channel's uploads playlist ID.
A given channel's uploads playlist ID is obtained upon querying the channel's own endpoint. The needed ID is to be found at .items.contentDetails.relatedPlaylists.uploads. Usually, an channel ID and its corresponding uploads playlist ID are related by s/^UC([0-9a-zA-Z_-]{22})$/UU\1/.
Note that you should query the Channels endpoint only once, then use the returned uploads playlist ID as many times as you need.
Also note that you may experiment using the fields parameter applied to your queries, as to get from the API partial resources only. However, I'm predicting that (I may well be wrong, since did not tested it) the cost of 3 points for querying PlaylistItems for its contentDetails object cannot be improved.
Here is a prototype URL:
https://www.googleapis.com/youtube/v3/playlistItems?key=APP_KEY&part=contentDetails&fields=items/contentDetails/videoId&maxResults=1&playlistId=PLAYLIST_ID

YouTube API v3 Search not returning all videos

I'm trying to retrieve all videos for a channel, and some are not being returned by the api. I cannot find anything in the spec that indicates why some would not be in the result set.
The call I'm making is:
https://www.googleapis.com/youtube/v3/search?type=video&key=__key_here__&channelId=UCxS2lX7728bTnmK1t21bYlA&part=id,snippet&maxResults=50&order=title
[To test this you'll need your own api key]
The first page of results is missing at least one video. The one from 8-15-2018, titled I LEARNED HOW TO DO A NEW TRICK!, which is located here, is not in the result set, even though it falls within the date range, and the first 50 results.
Does anyone know if this is a known issue?
I have verified that if I add the q parameter, with the video id, it will retrieve it.
You may refer with this link.
The API call that you should make if you want to get the videos in a channel is a youtube.playlistItems.list() with the playlistId of the "uploads" playlist for the channel. (This usually stars with UU..., but that's an implementation detail that might change in the future.
Here's an example of the call in the API Explorer.
Getting the same data via a search operation isn't guaranteed to return everything; the search index isn't a replacement for the backend data that you can obtain via the youtube.playlistItems.list() call. It's very much the same point raised in this blog post (though the focus there is on v2).
To summarize, to get all the uploads from a channel, you need to get the items from the uploads playlist for the channel using playlistItems.list on that playlist's ID rather than calling search.list on the channel ID.

Youtube videos' Topic Ids dataset / dump

While processing youtube videos, I'm working with the youtube's API v3. The cycle goes like this:
1) Get video
2) Request API for video's topic Id
3) Find the tuple(s) on my local Freebase dump
4) Do things.
For efficiency reasons I'd like to avoid the online request on step (2), and instead do it offline. Is there any datasets/dumps I can get, that store information like:
Youtube video's ID -> video's topic ID ?
Thanks in advance,
Orestes.
YouTube doesn't provide data dumps of video topicDetails (or any other data server by the YouTube Data API as far as I know).
There is not a store I know. But there are few things to make it more efficient. Instead of calling videos->list per each video, make all video Ids into a comma separated string and do one call. Also specify filters like items/contentdetails/topicId, so response would only return topicIds, instead of all other information.
That way you can get all your information at once, with less bandwidth.

YouTube Preferred Channels Feed or API

I'm looking to programmatically discover the YouTube Preferred channels (Examples: https://www.youtube.com/channel/UCiq_aAkP44mMpRx8VvQiF6w/channels?shelf_id=5204494150831773367&view=49 and https://www.youtube.com/channel/UCpXBkrx5YWAe8I9nbmLK_fA/channels?) but the channel pages with their AJAX lists is all I've found. Obviously it would be much easier to crawl an API or an RSS feed (or even a static HTML page!) and I've yet to find anything like that with each of the YouTube Preferred channel ids.
Am I missing something? Do these preferred channel lists really only exist in this one form?
Edit #1: I have tried to use the YouTube Data API to pull these "Preferred" channels' playlists via /channel/lists, but both efforts were a bust as the /channel/list only returned the single top-level channel and the playlists were empty.
Edit #2: I tried the solution from this: Youtube api get the channels from the Featured channels module and it did not work (despite this question being tagged as a duplicate of it).
You can use the channelSections.list endpoint with the Google Preferred channel id (UCiq_aAkP44mMpRx8VvQiF6w), the preferred channel ids are in the contentDetails separated in 1% and 5% groups
Example: https://developers.google.com/apis-explorer/#p/youtube/v3/youtube.channelSections.list?part=contentDetails&channelId=UCiq_aAkP44mMpRx8VvQiF6w&_h=1&

Get Video Information from ChannelD

I am looking for the json from where i can get information of video falls in specific channel(ChannelId is given). I tried below to get the same, but page not found showing.
https://www.googleapis.com/youtube/v3/search?key=***&channelId=UC39dDX5cE3WxN5ObmCBsCCQ
Or any other effective way to fetch the information?
Api version 3 returns only json in responses. You find information at https://developers.google.com/youtube/v3/docs/
Channel information returns a playlist-id of the uploaded videos for a channel.
But using search can work too (Replace YourApiKey with your own key):
https://www.googleapis.com/youtube/v3/search?part=snippet&type=video&channelId=UC39dDX5cE3WxN5ObmCBsCCQ&maxResults=50&key=YourApiKey

Resources