Archival lists of most subscribed YouTube accounts? - youtube

Is there a way to find the top X YouTube accounts by subscriber count for Y year---say, the top 100 accounts in 2015? I don't see anything in the API docs, and while there are services like SocialBlade and VidStatsX, they don't provide archived lists, and the data is not captured on archive.org.

The standard Analytics API doesn't provide this functionality. You can get data about views, likes, and dislikes, but you must provide one or more channel IDs.
Required Parameters: ids
Identifies the YouTube channel or content owner for which you are
retrieving YouTube Analytics data.
To request data for a YouTube
channel, set the ids parameter value to either channel==MINE or
channel==CHANNEL_ID, where CHANNEL_ID identifies the currently
authenticated user's YouTube channel.
To request data for a YouTube
CMS content owner, set the ids parameter value to
contentOwner==OWNER_NAME, where OWNER_NAME is the CMS user ID for the
user.
Use the Try this API section on the reference page to test the possibilities.

Related

Liked videos for a set of users via YouTube data API

For a given list of users (via their email address), I am interested in getting their most recent liked videos.
Also what is not clear is - is it possible to access any liked videos for users for which you don't have authorization?
I have seen solutions via getting the 'Liked' playlist, however it appears this can only be accessed for myself.
Note that a given user's list of liked videos -- of which playlist ID indeed can be retrieved via Channels.list API endpoint through the property contentDetails.relatedPlaylists.likes -- is private data pertaining that user.
Hence you're not going to be able to obtain from the API the kind of information you're looking for -- except if you issue an authorized API endpoint call, implying that the respective call is to be made relative to your own YouTube account (i.e. channel), in which case you'll get the ID of the playlist of videos that you liked yourself.
There's also the possibility of employing the parameter onBehalfOfContentOwner -- applied to each of the API endpoints Channels.list and PlaylistItems.list:
onBehalfOfContentOwner (string)
This parameter can only be used in a properly authorized request. Note: This parameter is intended exclusively for YouTube content partners.
The onBehalfOfContentOwner parameter indicates that the request's authorization credentials identify a YouTube CMS user who is acting on behalf of the content owner specified in the parameter value. This parameter is intended for YouTube content partners that own and manage many different YouTube channels. It allows content owners to authenticate once and get access to all their video and channel data, without having to provide authentication credentials for each individual channel. The CMS account that the user authenticates with must be linked to the specified YouTube content owner.
For thorough info about these things see the document Acting on behalf of a content owner, specifically the section relative to YouTube Data API v3.

How to know `on_behalf_of_content_owner` for Youtube Analytics API?

I want to use list_batch_report_definitions method in Youtube Analytics API V2.
http://www.rubydoc.info/github/google/google-api-ruby-client/Google/Apis/YoutubeAnalyticsV1/YouTubeAnalyticsService#list_batch_report_definitions-instance_method
But I don't know what is on_behalf_of_content_owner and how to get it.
onBehalfOfContentOwner string
The ID of the content owner for whom the API request is being made. If the request does not specify a value for this parameter, the
API server assumes that the request is being made for the user's own
channel.
ID Identifies the YouTube channel or content owner for which you are >retrieving YouTube Analytics data.
Note: Content owner reports are only accessible to YouTube content partners who participate in the YouTube Partner Program.
I suspect once you have been accepted into this partner program you will be given access to the content owner id.

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.

YouTube Analytics API Questions

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).

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