I'm trying to get the YT Data API to work and it kinda does work, but I've came across a few inconsistencies where I'm not sure if they are there for a reason.
First: I'm trying to build a discord bot which can announce streams from youtube. Therefore it needs to be able to retrieve channel ids by usernames and live stream information by the retrieved channel id. I want to use the channels endpoint and the search.list endpoint, such that it can do these things automatically (even though it's very expensive).
I'm using this request from the search.list endpoint https://www.googleapis.com/youtube/v3/search?part=snippet&channelId=[channelID]=video&eventType=live&key=[myKey] to check if it actually works. So I picked two completely random channels which were streaming at the time, took the channel id and sent the request. However I only got a response for one of the two channels. The empty response didn't feature any items which would contain the relevant information. I don't really know, why this is.
Related
I've got a YouTube user, which doesn't contain a YouTube channel. But the YouTube data API does return a channel, if I query the youtube.channels.list API method by using the "mine=true" attribute like in following example (1).
Example:
(1) Returns a channel (mine=true; by using OAuth):
https://developers.google.com/apis-explorer/#p/youtube/v3/youtube.channels.list?part=snippet%252CcontentDetails%252Cstatistics&mine=true&_h=5&
This query (1) returns a channel which contains a channelId. Now I'm trying to query for the playlists of this channel by using the previously returned channelId.
(2) Returns a 404 "channel not found" error
https://developers.google.com/apis-explorer/#p/youtube/v3/youtube.playlists.list?part=snippet&channelId=UCIReEy02ibumfYhQP3-0drQ&_h=4&
As described here it's possible to use a YouTube account without a channel but with limited functionality like using playlists:
With a Google Account, you can watch and like videos and subscribe to channels. However, without a YouTube channel, you have no public presence on YouTube. Even if you have a Google Account, you need to create a YouTube channel to upload videos, comment, or make playlists. You can use a computer or the YouTube mobile site to create a new channel.
What's the reason query (1) is returning a channel even if a YouTube account doesn't contain a channel?
BR
ninsky
[1] Returns a channel (mine=true; by using OAuth):
Because of every account on youtube itself a channel. They can do all the things they want like any channel can do e.g. upload videos. Also, we can make multiple channels under the same account.
[2] Doesn't return a channel (forUsername=UCIReEy02ibumfYhQP3-0drQ; by/without using OAuth):
Please make sure UCIReEy02ibumfYhQP3-0drQ is a valid username
I'm building something with the YouTube API. I've found a few oddities so far. The first thing is that a channel can have a title of 'blah blah - Topic' so you probably want to screen those out if you want to retrieve channels with their own content. If I'm right in my thinking, these are just channels with Playlists. Example: https://www.youtube.com/channel/UC6tQSWkTxbPNaJ_LQ-Ia6jQ/
Also be aware that channels don't have to have a unique title.
Finally there are many channels that return nothing from the API Channels.List method, even though they are channels. I'm still figuring these out. I don't think they are returned from searching through the API, but if you get your Channel IDs from another source then this could be an issue.
Can any one help me to find the user id / email for this Youtube Channel.
I don't have any programming background.
https://www.youtube.com/channel/UCGS6tPWTNYLy04JSFUrT7ew
No you won't be able to in new API v3 documentation explains
The biggest takeaway for developers using the older Data API v2 is
that you must be aware that not every YouTube channel has a unique
username. Fortunately, every YouTube channel is guaranteed to have a
unique channel ID associated with it, represented by the value in the
tag, and that’s the value that we recommend developers
use instead of usernames. For instance, if you have a database that
maps YouTube usernames to information about that channel, your older
entries should continue to work. (Existing channels won’t lose their
usernames.) However, as time goes on, it will become more and more
likely that you’ll have to work with channels that can’t be uniquely
identified by a username.
A channel doesn't have an email address associated to it you can see that by checking the Channel resource. If you are authenticated with a user and you can use the token info end point to get info about the user
https://www.googleapis.com/oauth2/v3/tokeninfo?id_token=XYZ123
You can also go though the people api
https://developers.google.com/people/api/rest/v1/people/get
For both those calls you must be authenticated. You cant get email for a user who you dont have access to
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.
YouTube recently released the new brandingSettings return object in to the response of /channel/list, but it seems very inconsistent in returning data.
What are the situations where that will return data?
Is it only returned for YouTube Partner API accounts? I've been testing with both, but seem to get some of it for authenticated accounts using non-Partner keys.
Can I only get the full data set (image, channel, hints, ...) if the partner API account is a manager of the requested channel?
Is it limited to users using the new channel layout?
I'm just getting a very sparse data when testing it on both channels I have authorized, authorized and managed, and public, so any information on this would be very helpful.
https://developers.google.com/youtube/v3/docs/channels#properties
The brandingSettings part is supported for all types of channels, and should be modifiable when you're authorized as the channel itself, or via delegation using the onBehalfOfContentOwner= parameter. You can retrieve it's current settings using youtube.channels.list(part='id,brandingSettings', mine=true), make changes to the fields, and then pass in the modified JSON to youtube.channels.update(part='id,brandingSettings')
I'm fairly sure that only the latest channel layout is supported.
The one field that can't be updated is the channel title, as that needs to be changed via Google+ for linked channels (and the decision was made not to make it editable via the API for non-linked channels).
I'm new to the YouTube Analytics API, and had a couple of questions:
In order to retrieve Analytics reports, I have to specify the channel ID for the "ids" parameter. How do I find the channel ID for the OAuth-authenticated user? I saw in the Sample Application that I can call Channels.list method in the Data API (V3) and use the "mine=true" parameter. Is this guaranteed to return a single channel? If not, how do I know which channel is the right one? What's the recommended way of finding a user's channel ID?
Once I have the channel ID, I can begin querying for Analytics data. I'd like to query the "views" metric for the channel for the entire history of that channel. The question is, how do I know how far back to query? Is there a channel start date? The Channels.list method mentioned above doesn't return the snippet.publishedAt date for my channel so that doesn't seem to be a reliable way. How else do I know when to stop? I guess I could query back until 2005 or so when YouTube was founded but that seems like a bad approach. Any suggestions?
The Analytics API supports reports for channels as well as content owners. Once a user authenticates via OAuth, how do I know if that account is a regular YouTube account vs a CMS content owner account?
Any help would be greatly appreciated!
The recommended approach is to do a channels.list(mine=true). The first result returned will be the channel corresponding to the currently authorized user. (channels.list() returns a list of channels because there are other combinations of request parameters that could result in more than one channel being returned.)
Going back to some arbitrary date in the past should be harmless. 2005, 2000, etc. The YouTube Analytics backend should know how to properly deal with that, and you'll obviously only get stats that date back to the first views associated with your channel.
The value of the ids= parameter tells the API whether you want to do a report against a channel associated with the current authorized user (ids=channel==UC...) or against channels/videos that you have access to as a CMS content owner (ids=contentOwner==CONTENT_OWNER_NAME).