How I retrieve the chanel list using youtube api? - youtube

In an youtube account I have more channels.
Exists an api call to retrieve all the channels for my account?
I want to upload videos to different channels in function of some video properties. I think that the problem is that I authorize access to my global account don't give automatic authorization for all channels. I have a refresh-token for offline upload (I use this refresh token to retrieve the token for video upload).
If I retrieve channel list from api, always return only one channel and not all my channels.

You are going to need to authenticate once for each channel. The YouTube API is different then other Google APIs.
Refresh tokens are - project, channel based not project, user based.
So if you have five channels and you want to access them all you will need five refresh tokens one for each channel.

Related

Can GET channel list with mine=true return more than one channel?

I am working on integrating our app with youtube and I need to get user's channel id after logging on. Is there any chance that, when using /youtube/v3/channels?part=id&mine=true endpoint, I will get more than 1 channel in result list?
I tried to create more channels using the same account, but it always resulted in creating new google account, and then having ALWAYS one channel in the result list. But maybe there is some kind of (legacy?) way to create more channels "attached" to the same google account.
No, because when you authenticate, you have to choose to which channel you want to be authorized. And the token will be valid only for that channel.

Multiple Youtube channels on 1 account. How to restrict provided API key to only 1 channel?

I need the Youtube API key from a client just to populate a link list of their recent videos.
The client expressed they have one account with multiple youtube channels attached to the one google account. For security they are asking if the API can be restricted to one youtube channel. I just fetched the data and displayed it im not a youtube API expert so i am unsure how to direct them. They want the key they provide to only allow data fetched from the specific channel? Is that possible in the API settings when creating the key?
(google search was unhelpful and the docs didnt really mention multiple channels)
Thanks for any insight.
Api keys are only able to access public data. For example public videos uploaded to youtube.
If you want to access private user data then you are going to need to use Oauth2 and authorize the user.
How you authorize the user depends upon which language you are using. You should consult the documentation Authentication
When you authorize a user then will be able to pick which channel to grant you access to. This will give you an access token that you can use to access the data on that channel.

How can I use Youtube Analytics API without OAuth?

I would like to extract youtube channel analytics. Is it possible to extract information like subscriber count over a period of time, number of views over a period of time, region based subscription and so on?
From the documentation:
All YouTube Analytics and YouTube Reporting API requests must be
authorized by the channel or content owner that owns the requested
data.
And the only authentication method mentioned in the docs are the OAuth 2.0 protocol for authorizing access to private user data.

How do I get a list of YouTube channels, and associated channel URLs (user or channel), owned by an authenticated user

We use the following call to get ChannelID's for an authenticated user and it works well for most cases. Some YouTube user connect their channels to a Google+ page and this fails for one of our users in that situation. In that case, the call only returns the channelID associated the user's email account used for authentication, not all channels owned by the user.
System.IO.Stream resultStream = service.Query(new Uri("https://www.googleapis.com/youtube/v3/channels?part=id%2Csnippet%2CcontentDetails%2Cstatistics%2CtopicDetails&mine=true&key=" + GlobalSettings.developerKey));
Also, we construct the channel URL by appending the channelID to the following URL.
http://www.youtube.com/channel/
However, some channels us a user name and path instead of channelID. How can I detect that the type is user instead of channel? In that case the user name is appending to the following path. The Google+ user's main channel uses this path with a user name.
http://www.youtube.com/user/
A few things:
In v3 of the YouTube Data API, you're forced to work with channel ids everywhere. This is a good thing. Channel ids are the only universal way of identifying channels! Legacy usernames used to serve that purpose as well, but the number of channels without legacy usernames is increasing by the day, so writing new v2 code that relies on legacy usernames is not recommended (and isn't possible in v3).
When making a channels.list(..., mine=true) call, you're always going to get back exactly one channel. The channel you get back will depend on which channel was chosen when you went through the OAuth 2 flow—there's a picker within that flow that lets you choose whichever channel you'd like if your Google Account happens to have access to more than one channel. If you want to operate on a different channel, you need to explicitly obtain an OAuth 2 token for that channel.
channel.list(..., managedByMe=true) can return multiple channels, but that API call is only relevant to YouTube content partners, and is used hand-in-hand with the onBehalfOfContentOwner parameter. Most developers can safely ignore this unless you know you're explicitly working with YouTube content partners' accounts.
The URL to visit a channel's page isn't returned anywhere in the v3 API response—that's true, and maybe it should be (feel free to file a feature request). If you want to manually construct the URL, you can use http://www.youtube.com/channel/CHANNEL_ID, where CHANNEL_ID is the standard UC... value that is used everywhere else in v3. That should produce a valid URL regardless of whether there's also a legacy username for the channel.
The only way that I have been able to do this is to use the v2 API, instead of v3. Specifically, you can use the same OAuth token, but access this API endpoint:
https://gdata.youtube.com/feeds/api/users/default?v=2
It will return an XML doc that contains both a URL to the user's channel (using the channel id), as well as the YouTube username.
See https://developers.google.com/youtube/2.0/reference#User_profile_entry for more info.

Can Youtube v3 API be used currently for retreiving data of channels that user is not associated with?

I want to know if we can use Youtube V3 API to retrieve channel data, videos etc when the channel requested is not the authenticated user's own channel.
The documentation for v3 youtube api (https://developers.google.com/youtube/v3/docs/channels/list#try-it) says "The list method returns a collection of zero or more channel resources that match the request criteria. At this time, this method does require an authenticated user, and the API only supports requests to retrieve information about the channel that is associated with the currently authenticated user."
Example in V2 it is http://gdata.youtube.com/feeds/api/users/{user_name}, what is the equivalent in v3 ? Is it available yet ?
You can request a channel by ID e.g. Lady Gaga channel:
https://www.googleapis.com/youtube/v3/channels?id=UCNL1ZadSjHpjm4q9j2sVtOA&key=AIzaSyCR5In4DZaTP6IEZQ0r1JceuvluJRzQNLE&part=snippet,contentDetails
The plan is to support retrieving both channel profile information and the ids for the uploads/favorites/playlist/etc. feeds for a given channel in v3. It's not quite yet supported, but should be around the time of the public launch. (Which, I can't commit publicly to a date for that at this time.)

Resources