Liked videos for a set of users via YouTube data API - youtube-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.

Related

Archival lists of most subscribed YouTube accounts?

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.

Permissions to access someone's private videos on YouTube

We're working on an integration with youtube channels (using Youtube Data Api v3). We need to access the videos (private also) on our user's channels.
The flow is the following:
User authorizes his/her youtube account on our site using OAuth.
We show user the list of videos on user's youtube channel.
User selects some of them (they can be private) and sends us for processing.
We need to somehow access the actual video files which the user asks us to process.
The issue is that youtube does not give any streaming URLs or download links.
Looks like, the API provides only iframe embedded code, which works ONLY for the browser, where the user is actually logged into youtube.
How can we access(can we?!) the private video, if we have the OAuth access-token of the video owner?
The YouTube Data API lets you incorporate functions normally executed on the YouTube website into your own website or application. The lists below identify the different types of resources that you can retrieve using the API. The API also supports methods to insert, update, or delete many of these resources. This in a sense means that you can see most of what you can see on the YouTube website including uploading new videos.
Downloading Youtube videos is against their Terms of Service, so the API does not support that.
Page linked above refers to Youtube ToS that states:
You shall not download any Content unless you see a “download” or similar link displayed by YouTube on the Service for that Content.
YouTube partners may have access to this feature in their API (no idea i have never seen the api), if you have access to this i suggest you contact your manager directly they should be able to instruct you on how to access it assuming the feature exists.

Not being able to choose the right channel when using OAuth 2.0 for Web Server Applications flow

My app follows the server side authorization flow as described in https://developers.google.com/youtube/v3/guides/auth/server-side-web-apps. I force prompt=select_account.
In the most basic case, on "Step 3: Google prompts user for consent", the user sees a screen with one or more accounts titled "Choose an account". If the account that the user chooses only has a single channel associated with it, the flow then proceeds directly to "Step 4: Handle the OAuth 2.0 server response".
If the user has many channels associated with the account then the user might see another screen titled "Choose your account or a brand account".
For me personally I have two Google accounts: personal and work account and I see them both on the "Choose an account" screen. If I choose my personal account, I get directly to the app. If I choose my work account I see the additional screen where I can choose my "personal" work YouTube channel/account or the company wide shared channel/account. In total I can manage and access 3 YouTube channels/accounts.
The problem is that some users don't see all of their channels listed in the "Choose your account or a brand account". If the users are logged in to YouTube at the same time, they can still access all of their channels from the top right corner account selector on YouTube, but they can't see them at all in the selector. I've tried calling YT API channels.list in these kinds of cases but it doesn't return the missing channels, only the one the user picked from the selector.
It feels like I'm missing something obvious here, but since I don't have much control over the OAuth flow, I'm not sure how to go about fixing this. Is this even a problem on my end or do I just need to instruct the users to do something on their end?
Possibly related things:
YouTube APIs - Access mutiple youtube channels (Brand Accounts) using Google Admin account
YouTube API v3 get all channels associated with a logged in user
Youtube Brand Manager API V3 Support
Content owner "umbrella" accounts https://support.google.com/youtube/answer/6301188
default channel https://support.google.com/youtube/answer/6019090?hl=en
https://youtube-eng.googleblog.com/2013/06/google-page-identities-and-youtube-api_24.html
"Default channel with main account authorization" https://issuetracker.google.com/issues/35177410
It could be that the unlisted accounts are accounts that the users are not owners of but just managers for and where the flag onBehalfOfContentOwner is not set.
In the channels.list API there are the parameters
managedByMe boolean
This parameter can only be used in a properly
authorized request. Note: This parameter is intended exclusively for
YouTube content partners.
Set this parameter's value to true to instruct the API to only return
channels managed by the content owner that the onBehalfOfContentOwner
parameter specifies. The user must be authenticated as a CMS account
linked to the specified content owner and onBehalfOfContentOwner must
be provided.
and
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.

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.

Resources