get the title on live video in youtube using API YouTube V3 - youtube

i am using API Live Streaming youtube to retrieve list of live chat messages on youtube video using id_video, exits serveral properties that appear in this resource such as snippet.liveChatId, snippet.displayMessage which i can found them from this ressource,
so my question is how can i get the title on live video in channel youtube which is not for me ?
thanks

You may want to check this documentation. The items[] property will return a list of live streams that match the request criteria.
{
...
},
"items": [
liveStream Resource
]
}
The following JSON structure shows the format of a liveStreams resource:
{
"kind": "youtube#liveStream",
"etag": etag,
"id": string,
"snippet": {
"publishedAt": datetime,
"channelId": string,
"title": string,
"description": string,
"isDefaultStream": boolean
},
...
}

Related

how to map youtube handles to channel IDs

Youtube recently rolled out handles feature where they gave users youtube.com/#xxx type usernames, when visited these URLs show user's channel but I can't find any documentation or reference in API repositories.
How to extract youtube user channel ID from their handle?
One more time YouTube Data API v3 doesn't provide a basic feature.
I recommend you to try out my open-source YouTube operational API. Indeed by fetching https://yt.lemnoslife.com/channels?handle=#HANDLE you will get the YouTube channel id you are looking for in item["id"].
For instance with the YouTube channel handle #WHO, you would get:
{
"kind": "youtube#channelListResponse",
"etag": "NotImplemented",
"items": [
{
"kind": "youtube#channel",
"etag": "NotImplemented",
"id": "UC07-dOwgza1IguKA86jqxNA"
}
]
}

How to detect official artist channel using youtube api?

How to detect is it official artist channel or not, using youtube api? Official channel has special label next to title, like this one https://www.youtube.com/channel/UCBQZwaNPFfJ1gZ1fLZpAEGw, but it doesn't appear in title from api.
One more time YouTube Data API v3 doesn't provide a basic feature.
I recommend you to try out my open-source YouTube operational API. Indeed by fetching https://yt.lemnoslife.com/channels?part=approval&id=CHANNEL_ID, you will get whether or not the given channel is an official artist in item["approval"] by checking if this value is Official Artist Channel.
For instance the YouTube channel UC0aMaqIs997ggjDs_Q9UYiw is an official artist channel, with this channel id you would get:
{
"kind": "youtube#channelListResponse",
"etag": "NotImplemented",
"items": [
{
"kind": "youtube#channel",
"etag": "NotImplemented",
"id": "UC0aMaqIs997ggjDs_Q9UYiw",
"approval": "Official Artist Channel"
}
]
}

Get a YouTube channel uploaded video list by publish date

I am aware of similar questions being asked before, but not this exact one, so please bear with me...
I want to reproduce a channel's uploaded videos list as they appear on YouTube's web page (broken into pages and sorted by publish date).
To do this, I am trying to get a list of VideoIDs from a YouTube channel that's sorted by publish date (by YouTube, not my code since there could be 1000's of videos in a playlist and YouTube limits to 50 results per query which can add up when I only want to show the user the first 25 entries).
Initially, I was using this YouTube Data API v3 Search query:
https://www.googleapis.com/youtube/v3/search?key=[APIKey]&channelId=[ChannelID]&part=snippet,id&order=date&type=video&maxResults=25
However, as some of the previous posts on stackoverflow mentioned (YouTube API v3 Search not returning all videos), this method does not guarantee to return all videos and indeed, some videos are missing from the result, making use of this query problematic.
I then saw this google video in some of the posts:
https://www.youtube.com/watch?v=RjUlmco7v2M
In the video, it is explained that you must first get the 'uploads' playlist for a channel (I'm also grabbing the channel's title and thumbnail in this query), which I do using:
https://www.googleapis.com/youtube/v3/channels?key=[APIKEY]&part=snippet,contentDetails&id=[ChannelID]
And once I have the 'uploads' playlist ID, I query:
https://www.googleapis.com/youtube/v3/playlistItems?key=[APIKey]&playlistId=[PlaylistID]&part=snippet,id&order=date&type=video&maxResults=25
However, the returned entries are not sorted by the publish date and according to the documentation (https://developers.google.com/youtube/v3/docs/playlistItems/list), there is no optional "order" parameter associated with this query.
With all these issues in mind, how do I get the first 25 entries of the 'uploads' playlist sorted by publish date without downloading the entire playlist so I can faithfully recreate how the YouTube website is listing videos.
After making some tests and thanks to this answer (and the next answers too) I was able to retrieve the information you need using the YouTube Data API v3 and here is how I made it:
First, in your question you're using the "search" API - since I don't know which criteria you're using in the search request, I omitted it for get direct to get the "upload" playlist id from a given channel_id.
Using the channel_id = UCT2rZIAL-zNqeK1OmLLUa6g (which belongs to "Microsoft HoloLens"), I use the "channels" API for retrieve the uploads playlist id.
Here is the URL request for retrieve the "upload" playlist id from the channel_id previously mentioned:
https://www.googleapis.com/youtube/v3/channels?part=id%2Csnippet%2CcontentDetails&fields=items(contentDetails%2FrelatedPlaylists%2Fuploads%2Csnippet%2Flocalized)&id=UCT2rZIAL-zNqeK1OmLLUa6g&key=<YOUR_API_KEY>
Explanation:
part: set the snippet and contentDetails parts for retrieve the following:
fields: from the snippet part: (localized, description and title) and from the contentDetails part: (relatedPlayLists and uploads).
id: channel_id used in this request.
Here are the results from this request:
{
"items": [
{
"snippet": {
"localized": {
"title": "Microsoft HoloLens",
"description": "The official YouTube channel of Microsoft HoloLens. Transform your world with holograms. Visit HoloLens.com for more info."
}
},
"contentDetails": {
"relatedPlaylists": {
"uploads": "UUT2rZIAL-zNqeK1OmLLUa6g"
}
}
}
]
}
Check the value of the uploads property in the
contentDetails section. This value will be used in the next API request.
You can also check these results in the Google API Explorer demo I prepared for make this request.
Once retrieved the uploads value (as specified in previous lines), now it's time to use the "playlistItems" API for build the following URL:
https://www.googleapis.com/youtube/v3/playlistItems?part=snippet%2CcontentDetails&playlistId=UUT2rZIAL-zNqeK1OmLLUa6g&fields=items(contentDetails(videoId%2CvideoPublishedAt)%2Csnippet%2Ftitle%2Cstatus)&maxResults=25&key=<YOUR_API_KEY>
Explanation:
part: set the snippet and contentDetails parts for retrieve the following:
fields: from the snippet part: (title and status) and from the contentDetails part: (videoId and videoPublishedAt).
playlistId: is the playlistId used in this request - (that is, the uploads value).
maxResults: set to 25.
Here are the results from this request:
{
"items": [
{
"snippet": {
"title": "Microsoft Windows Mixed Reality update | October 2018"
},
"contentDetails": {
"videoId": "00vnln25HBg",
"videoPublishedAt": "2019-01-04T17:43:47.000Z"
}
},
{
"snippet": {
"title": "How to use Spectator View for mobile devices"
},
"contentDetails": {
"videoId": "3fXlPw_FGLg",
"videoPublishedAt": "2018-10-15T17:13:42.000Z"
}
},
{
"snippet": {
"title": "Microsoft HoloLens: Visualizing the next mission to Mars."
},
"contentDetails": {
"videoId": "XVBbJ4EtAQY",
"videoPublishedAt": "2018-07-02T16:30:26.000Z"
}
},
{
"snippet": {
"title": "Microsoft HoloLens: Making mixed reality plug and play."
},
"contentDetails": {
"videoId": "QwXcSekZKWE",
"videoPublishedAt": "2018-06-25T23:25:55.000Z"
}
},
{
"snippet": {
"title": "Microsoft HoloLens | Windows Mixed Reality HMD Exerciser"
},
"contentDetails": {
"videoId": "RU3OMjq_Yic",
"videoPublishedAt": "2018-05-14T16:58:43.000Z"
}
}
]
}
I check the order of the items and they are in sorted by videoPublishedAt value (new to old).
You can also check these results in the try-it funcionality found in the YouTube Data API v3 - official documentation.1
1 For this case, I was unable to use the Google API Explorer (as I used in the first request) because I always got a "backend Error".
{
"error": {
"errors": [
{
"domain": "global",
"reason": "backendError",
"message": "Backend Error"
}
],
"code": 500,
"message": "Backend Error"
}
}
I think this is because the Google API explorer is outdated.
If anyone want to check it out, here is the demo.
I'm also using the playlist ID to get a list of videos, however mine do seem to be sorted by date from newest to oldest. Note that Youtube returns a page token that you can use to get the next 25 (or in my case 50) videos. I'm querying the API this way:
https://www.googleapis.com/youtube/v3/playlistItems?part=snippet&pageToken= not_used_for_first_query&fields=nextPageToken,items(snippet(publishedAt,title,desc ription,thumbnails(default(url)),resourceId(videoId)))&playlistId=uploads_playlist_id&maxResults=50&order=date&key=your_api_key
This gets back in JSON response:
The video title
Publish date
Video description
Youtube URL for video
Video unique ID
Video thumbnail
You can see my working example at https://www.scriptbarrel.com

Is their a way to list the copyright claims of your video on Youtube using Youtube's API?

When you upload a video to YouTube you may get a Includes copyrighted content flag in the video manager. Then when you go and check the video you see a message under the "copyright" section:
You have x copyright claims on your video. and below this is a Details section displaying interesting information like:
"CONTENT","CLAIMANT","POLICY" and it shows the time region where this claimed content is located in the video. What i would like to know is if Youtube's or Google's API can give us this same information?
Try using Videos: list.
Send HTTP request using this format:
GET https://www.googleapis.com/youtube/v3/videos
If successful, this method returns a response body with this sample video resource:
"contentDetails": {
"licensedContent": boolean,
"regionRestriction": {
"allowed": [
string
],
"blocked": [
string
]
},
"status": {
"privacyStatus": string,
"publishAt": datetime,
"license": string,
"publicStatsViewable": boolean
}

How to get "transcript" in youtube-api v3

I have started using v3 of the YouTube apis on an android device, using the java client library. Some videos that I am interested in have transcripts that I can access on the web interface (like educational videos). Is there a way to access the transcripts, if present, using the v3 apis?
Thanks
I had the same problem with this... and spent like a week looking for a solution until I hit this:
https://stackoverflow.com/questions/10036796/how-to-extract-subtitles-from-youtube-videos
Just do a GET request on: http://video.google.com/timedtext?lang={LANG}&v={VIDEOID}
You don't need any api/oauth/etc. to access this.
With API v3 you can first grab the available transcripts with the snippet:
https://www.googleapis.com/youtube/v3/captions?videoId=U1e2VNtEqm4&part=snippet&key=(my_api_key):
{
"kind": "youtube#captionListResponse",
"etag": "\"DsOZ7qVJA4mxdTxZeNzis6uE6ck/aGHflncRxq1Uz6m1akhrOLUWUqU\"",
"items": [
{
"kind": "youtube#caption",
"etag": "\"DsOZ7qVJA4mxdTxZeNzis6uE6ck/IC7rNKkn3SQNdovFwR6fEabUYnY\"",
"id": "TqXDnlamg84o4bX0q2oaHz4nfWZdyiZMOrcuWsSLyPc=",
"snippet": {
"videoId": "U1e2VNtEqm4",
"lastUpdated": "2016-01-25T21:50:27.142Z",
"trackKind": "standard",
"language": "en-GB",
"name": "",
"audioTrackType": "unknown",
"isCC": false,
"isLarge": false,
"isEasyReader": false,
"isDraft": false,
"isAutoSynced": false,
"status": "serving"
}
},
{
"kind": "youtube#caption",
"etag": "\"DsOZ7qVJA4mxdTxZeNzis6uE6ck/5UP1qPkmq6mzTUaEVnFC8WqjFgU\"",
"id": "TqXDnlamg84o4bX0q2oaHw_Y53ilUWv6vMFbk0RL3XY=",
"snippet": {
"videoId": "U1e2VNtEqm4",
"lastUpdated": "2016-01-25T21:55:07.481Z",
"trackKind": "standard",
"language": "en-US",
"name": "",
"audioTrackType": "unknown",
"isCC": false,
"isLarge": false,
"isEasyReader": false,
"isDraft": false,
"isAutoSynced": false,
"status": "serving"
}
}
]
}
And then pick the transcript you want:
https://www.googleapis.com/youtube/v3/captions/id?id=TqXDnlamg84o4bX0q2oaHz4nfWZdyiZMOrcuWsSLyPc=
or
https://www.googleapis.com/youtube/v3/captions/TqXDnlamg84o4bX0q2oaHz4nfWZdyiZMOrcuWsSLyPc=
at which point you need provide an authorization key. Apparently a simple key isn't enough. Possibly because:
Quota impact: A call to this method has a quota cost of approximately 200 units.
Note the slight difference in the URLs (/caption/ versus /caption?).
All the lovely documentation is here:
https://developers.google.com/youtube/v3/docs/captions
I may be wrong, but I don't think there is yet a documented way to get the caption track via v3 of the API. If you're authenticating with oAuth2, however, your authentication will also be good for v2 of the API, so you could do a quick call to this feed:
http://gdata.youtube.com/feeds/api/videos/[VIDEOID]/captiondata/[CAPTION TRACKID]
to get the data you want. To retrieve a list of possible caption track IDs with v2 of the API, you access this feed:
https://gdata.youtube.com/feeds/api/videos/[VIDEOID]/captions
That feed request also accepts some optional parameters, including language, max-results, etc. For more details, along with a sample that shows the returned format of the caption track list, see the documentation at https://developers.google.com/youtube/2.0/developers_guide_protocol_captions#Retrieve_Caption_Set
Heres some code I wrote which grabs all the caption tracks from any youtube video without having to use the API. Just plug the video URL in the $video_url variable.
// get video id from url
$video_url = 'https://www.youtube.com/watch?v=kYX87kkyubk';
preg_match("#(?<=v=)[a-zA-Z0-9-]+(?=&)|(?<=v\/)[^&\n]+(?=\?)|(?<=v=)[^&\n]+|(?<=youtu.be/)[^&\n]+#", $video_url, $matches);
// get video info from id
$video_id = $matches[0];
$video_info = file_get_contents('http://www.youtube.com/get_video_info?&video_id='.$video_id);
parse_str($video_info, $video_info_array);
if (isset($video_info_array['caption_tracks'])) {
$tracks = explode(',', $video_info_array['caption_tracks']);
// print info for each track (including url to track content)
foreach ($tracks as $track) {
parse_str($track, $output);
print_r($output);
}
}
Probably the best way is using Youtube API 3. I'm trying it but you need an API key + OAuth 2.0 user. A fast solution is using captionsgrabber and parsing the returned HTML data.
Use example:
https://www.captionsgrabber.com/8302/get-captions.00.php?id=UJTY7ilwSq4
// Where the id is the youtube video id

Resources