How to get user specific recommended videos based on specific channel - youtube-api

How to get user specific recommended videos based on specific channel like - nba, nationalgeographic using YouTube API?
I am using the below API to get recommended videos.
https://gdata.youtube.com/feeds/api/users/default/recommendations?v=2&key=&access_token=
key -> I am passing my developer key
access_token -> I am passing authentication token.
Its returning me recommended videos of specific user. But I need recommended videos of specific channels like nba, nationalgeographic.
Can anyone please help for this.

I know this is old but in case anyone googling this comes across this answer, a workaround until there is a full recommendation API in YouTube API v3 is to use the Activity List feature, then just go through the results looking for "type": "recommendation":
https://developers.google.com/youtube/v3/docs/activities/list
GET https://www.googleapis.com/youtube/v3/activities?part=snippet&home=true&maxResults=50&key={YOUR_API_KEY}
(don't forget to use an auth token for a user for this to work)

Related

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.

Youtube v3 API comment retrieval with commentThreads.list endpoint

I am using commentThreads.list endpoint in Youtube v3 API to get all the comments for particular videos. This works well for us, however, this endpoint requires youtube.force-ssl scope which is a pretty sensitive one. The doc says that this scope is the only option. The issue is that the user gets a warning screen upon connecting the account:
At this point, users become concerned about the permissions that they are giving to our app, as youtube.force-ssl scope gives the app a bunch of sensitive permissions as "See, edit, and permanently delete your YouTube videos, ratings, comments and captions", according to the doc
Why Youtube v3 API comment retrieval with commentThreads.list endpoint requires such a sensitive scope and is there an alternative way to retrieve all comments for my videos? Now looks like the only option is to get through the verification.
P.S. I know that may seem more a discussion topic, however, that looks like an overkill to give such set of permissions to retrieve the information that is available publicly on the page, so I am looking for possible alternatives.

YouTube API from V2 to V3 migration

I'm still using old V2 api and now i get https://youtube.com/devicesupport.
My current request is:
https://gdata.youtube.com/feeds/api/users/{username}/uploads?alt=jsonc&max-results=15&v=2
There is no authentication required to make that call
Question:
Any idea how to achieve the same with new Google V3 API? I check documentation but didn't found answer for that.
I had the same problem with V3 api. I think you can't access videos informations without authentication anymore, but you don't need to use an OAuth to get a snippet from some video or search. I was searching a simple solution for my app, because I just want to request title, thumb and descriptions.
The new url will be:
https://www.googleapis.com/youtube/v3/videosid={VIDEO_ID}&part=snippet&key={YOU_API_KEY}
You need to access google developers console, enable youtube api and your public access key - on credentials (API KEY), so they can relate your app to all requests.
And I found this example in PHP if you need to parse JSON result:
http://www.leenooks.com/php/parsing-youtube-v3-json-with-php-examples.html
I'm still don't know all the limitations of V3, I was using V2 too, but maybe for uploads, or more control for youtube accounts you'll have to use OAuth.
I hope this will help you.

Using YouTube API v3 to tell if a channel has a live stream

The goal of my YouTube API call is, given a channelId, to return whether that channel is currently live streaming. This is the call I'm making currently:
https://www.googleapis.com/youtube/v3/search?part=snippet&channelId={CHANNEL_ID}&eventType=live&type=video&key={YOUR_API_KEY}
While this call is functional, there is a significant delay between the channel starting a live stream and this call returning the stream.
Is there a better call to use in the YouTube v3 API that doesn't require oAuth? The functionality of my app is read-only.
Thanks!
Probably late but still someone else would use it, i found the answer on google api docs:
https://developers.google.com/youtube/v3/live/docs/liveBroadcasts/list
(Scroll to bottom, you can use their onsite api to make calls on the fly)
The call you have to make is:
GET https://www.googleapis.com/youtube/v3/liveBroadcasts?part=id%2Csnippet%2Cstatus&mine=true&broadcastStatus=active&key={YOUR_API_KEY}
(atm, they have an issue wth the status field). You can remove the filter and check the returned results for
{ "status": { "lifeCycleStatus": "live"}}
And as per google docs:
Before you start
You need a Google Account to access the Google Developers Console, request an >API key, and register your application.
Register your application with Google so that it can submit API requests.
After registering your application, select the YouTube Data API as one of the >services that your application uses:
Go to the Developers Console and select the project that you just registered.
Open the API Library in the Google Developers Console. If prompted, select a >project or create a new one. In the list of APIs, make sure the status is ON for >the YouTube Data API v3 and, if you are a YouTube Content Partner, the YouTube >Content ID API.
Calling the Data API
The API request must be authorized by the Google Account that owns the >broadcasting YouTube channel.
You can check this link for generating an access(OAuth 2.0) token: https://developers.google.com/identity/protocols/OAuth2?hl=en
I hope this helps.
I was digging for a "cheaper" way to find if a channel is live to save some API quota. I attempted to use Konstantin's workaround by looking at the {channel/channel_id}/live but this appears to not work anymore.
The channel no longer redirects when a person is live. Instead it runs on that page.
If they have a username URL then /c/ works: https://www.youtube.com/c/USER_NAME/live
If they have don't have a username and use the default like UC4R8DWoMoI7CAwX8_LjQHig, then you need to use https://www.youtube.com/channel/USER_NAME/live
The /search call is rather expensive. If you are only allotted the initial 10k quota points, you'd run out of points after only 100 queries. That may not be a bother for some use cases, but it is nevertheless limited.
Instead, you can use Playwright and do the following:
page.goto("https://YouTube.com/channel/{channel id}/live")
Then check for a redirection which will happen when the channel is live:
const redirect = page.url()
If redirect contains a link to a YouTube video, then you know the channel is live. Otherwise it is not live and will yield a link similar to the one that's passed in to the goto() function.

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

Resources