Retrieve user by channel ID? - youtube

I am retrieving all of the videos for a given channel by:
'https://gdata.youtube.com/feeds/api/users/{username}/uploads'
When I go to a channel, such as: http://www.youtube.com/channel/UCXIyz409s7bNWVcM-vjfdVA I have the channel ID and I can quite clearly see the videos. Also, if I click on the 'Videos' tab I can see all the videos, but the URL changes to: http://www.youtube.com/user/majesticcasual/videos
I would like to take the channel ID and retrieve the username for the given channel such that I can query YouTube's API for the videos by channel ID. Is this possible?

If you retrieve this feed:
https://gdata.youtube.com/feeds/api/users/[channel_id]/
You'll get a response that includes an <author> element -- the <name> child of that <author> element is the username. It's also repeated in that same feed as <yt:username>.
Of course, that's kind of moot, because you can query by channelID directly:
https://gdata.youtube.com/feeds/api/users/[channel_id]/uploads
is the same feed as if you'd used the username. This works because the channel_id really is just the unique ID of someone's username.
If you want to use v3 of the API (Which is highly encouraged, as it's at production level now), you could use this feed:
GET https://www.googleapis.com/youtube/v3/playlistItems?part=snippet&playlistId=UUXIyz409s7bNWVcM-vjfdVA&key={YOUR_API_KEY}
Note that I've changed the channel id so instead of starting with UC (as all channel ids do), I'm passing in a value that starts with UU ... this is so you get back the uploads feed of the channel (you could also have it start with LL instead to get back the 'likes' feed, for example ... or even do a request to:
GET https://www.googleapis.com/youtube/v3/channels?part=snippet%2CcontentDetails&id=UCXIyz409s7bNWVcM-vjfdVA&key={YOUR_API_KEY}
To retrieve, in the contentDetails parameter, all of the playlists associated with that particular channel.

Related

Get all videos for a given user

I'm trying to find a way to retrieve all videos posted by a given user (eg: https://www.youtube.com/user/laliga/videos).
All the examples I've found online or the doc (https://developers.google.com/youtube/v3/docs/) seems to require either a playlist ID, channel ID or video ID.
Is there any way I can directly query the author's videos or am I forced to retrieve all playlists and then iterate over?
Thanks
You just need to map the user name to its channelID first via the YouTube API like so:
https://www.googleapis.com/youtube/v3/channels?forUsername=USER_NAME&part=id&key=API_KEY
Full docs: https://developers.google.com/youtube/v3/docs/channels/list
Then you can make a Videos:List call with that channelID to get the videos.
1)take your google key id and channel id and put inside below url
https://www.googleapis.com/youtube/v3/search?key=APIKEY&channelId=CHANNELID&part=snippet,id&order=date&maxResults=20
ex
https://www.googleapis.com/youtube/v3/search?key=adsjsdakhkjshd&channelId=sdahghsadhgj&part=snippet,id&order=date&maxResults=20

YouTube API - get tags for all videos with playlist query

I'm querying YouTube channels to retrieve playlist metadata like this:
https://www.googleapis.com/youtube/v3/playlistItems?part=snippet%2CcontentDetails&maxResults=5&playlistId={PLAYLIST_ID}&key={API_KEY}
This query returns an array of all of the videos on the channel. Each object in that array includes various fields that provide metadata on each video, but none of these fields include the tags associated with the video. I can get that data using a query like this:
https://www.googleapis.com/youtube/v3/videos?key={API_KEY}&fields=items(snippet(title,description,tags))&part=snippet&id={VIDEO_ID}
The problem with that is that now I need to issue a separate query for every single video that comes back in the first query.
So, my question is, is there a way that I can get these tags included as part of the initial JSON object from the first query? Can I add any parameters that will request this data be included with that response?
Thanks for any help!
Short answer: No.
The PlaylistItems: list documentation does not show a way to get video tags from the playlistItems endpoint. The only parts available are id, snippet, status and contentDetails and neither of those contain tags.
However!
You do not have to make a request for each video in the playlist! The documentation states:
The id parameter specifies a comma-separated list of the YouTube video ID(s) for the resource(s) that are being retrieved. In a video resource, the id property specifies the video's ID. (string)
That means you can supply multiple, comma-separated video ids to the videos endpoint.
Example:
GET https://www.googleapis.com/youtube/v3/videos?part=snippet&id=kOkQ4T5WO9E,a59gmGkq_pw,Io0fBr1XBUA&key={YOUR_API_KEY}
So in total, it will cost you two requests to get the tags of all videos in a playlist.*
*In practice, you might have to make more than two requests. If I remember correctly, YouTube limits the returned items to 50 per request. Thus, if the playlist contains more than 50 videos, you will have to make another request with the pageToken parameter set.

youtube v3 api : get all live streaming playlist ids of a channel

I have two "Live streaming/live broadcast saved playlists" in following youtube channel --> https://www.youtube.com/user/swaminarayanlive.
I am trying to retrieve all the "live streaming / live broadcast playlists" of a channel using new youtube v3 api by using the below link-->
https://www.googleapis.com/youtube/v3/playlists?part=snippet&channelId=UCBkNpeyvBO2TdPGVC_PsPUA&key={YOUR_API_KEY}
here i can get the info of playlists which are not live streams or live broadcast. and not able to get the same for the live one.
Please help me how can i get that for live one using youtube v3 api
I was researching another issue with the API when finding this, and when I saw that this was never resolved, I decided to look into it. It turns out that this is related to that other issue.
The YouTube API v3 lacks support for saved playlists. The channel swaminarayanlive did not create the playlists, only saved them from the channel BhujMandir.
The workaround in your case would be to retrieve the playlists of BhujMandir and extract the response snippets with "title" parameters containing the word "Live".
You would need to go through the pages and search each one for this, since there is a limit to how many results an API response can show at once. Currently it's 50.
So, you would use the following to get the first page of playlistItems:
GET https://www.googleapis.com/youtube/v3/playlists?part=snippet&channelId=UCVItNtUctAknegvmYcMhUQg&maxResults=50&key={YOUR_API_KEY}
This will return an API response containing the properties "kind" (which will have the value "youtube#playlistListResponse") and "etag". If there are more than 50 results, there will also be a "nextPageToken" property. (On a page that is not the first, there would also be a "prevPageToken" property.)
After these properties, there are two blocks. One called "pageInfo", containing info about how many results (playlists) there are and how many are shown per page, and one block called "items", containing the resulting playlistItems.
You would look through the items block for any playlistItem with a title property (which is a string) containing the substring "Live" and get the id properties of those. You would then look on the next page by using the nextPageToken's value in a new HTTP request, like so:
GET https://www.googleapis.com/youtube/v3/playlists?part=snippet&channelId=UCVItNtUctAknegvmYcMhUQg&maxResults=50&pageToken=[nextPageToken_value_here]&key={YOUR_API_KEY}
As of now, the two playlists you're looking for are on the pages with tokens CJYBEAA and CMgBEAA.
I think that where is the {YOUR_API_KEY} you should change this code and insert the name of your application program interface

youtube analytics ids value

I am trying to use Youtube analytics but I am not sure how to fill out the parameters properly
Here is the form I am trying to fill out: https://developers.google.com/apis-explorer/#s/youtubeAnalytics/v1/youtubeAnalytics.reports.query
How do you find out the value of ids?
It states: Unique channel or content owner ID for retrieving YouTube Analytic data. Either channel==C or contentOwner==O where 'C' is the encrypted channel ID and 'O' is the content owner name. (string)
I have tried contentOwner=={myapikey}
where {myapikey} is an api key for my google app
How do I get the proper value of ids?
My goal is to execute a query on the above link.
You can get the values for the currently logged in user that you can put into ids=channel==%here$% using an authenticated call to https://developers.google.com/youtube/v3/docs/channels/list
For ids=contentOwner==%here%:
This is for the case where your user is associated to a YT content owner. Right now you would need to ask your client (a YT content owner) to get this ID. The client can get it from their partner manager.

How do I get a list of uploaded videos for a certain channel with the new YouTube Data API (V3)?

I am trying to get a list of video ids for all uploaded videos to a channel. I would also like to use the new version of the YouTube Data API (V3). How do I do this?
You have to get the upload playlist id to get each videos uploaded. To get that, you need to get the channel id. After you have the playlist id from the channel id, it is pretty simple. I have written out the steps for all three below.
Also, we offer PubSubHubBub which allows you to be alerted every time a new video is added to a channel, or you could use SUP (V2) to see which resources have changed before making the calls.
Instructions to get video ids for all uploaded videos for a channel in V3
Get the channel id for the channel you want (you probably only need to do this once, then you can save it)
Use search.list
Set type to channel
Set q to the name of the channel you want
Grab the channel id (something like this: "channelId": "UC0X2VuXXXXXXXXXXXXXXXX")
Get the playlist id for the channel uploads using the channel id from step 1 (you probably only need to do this once, then you can save it)
Use channels.list
Set id to UC0X2VuXXXXXXXXXXXXXXXX from step 1
Grab the uploads key from contentDetails (something like this: "uploads": "UU0XXXXXXXXXXXXXXXXXXXX")
Get the videos via the playlistitems in the playlist using the playlist id from step 2
Use playlistItems.list
Set playlistId to UU0XXXXXXXXXXXXXXXXXXXX from step 2
Go through each PlaylistItem and pull out the video id
In the meantime, there is a much easier way:
Use the channels.list
set forUsername = [CHANNELNAME]
set part = contentDetails
grab $data->items[0]->contentDetails->relatedPlaylists->uploads --> [PLAYLISTID]
Use playlistItems.list
Set playlistId = [PLAYLISTID] from step 1
Go through each PlaylistItem and pull out the video ids

Resources