How to create persistent livebroadcast? - youtube

I develop the mobile app with livestream feature and I need to get default livebroadcast with default livestream data.
When user didn't enable livestreams in his youtube account I show him message with link to https://www.youtube.com/live_streaming_signup .
After if user enabled livestreams in his youtube account I can't get default livebroadcast with broadcast type persistent.
My request url is: https://www.googleapis.com/youtube/v3/liveBroadcasts?part=contentDetails&mine=true&broadcastType=persistent&access_token=
My response is:
{
"kind": "youtube#liveBroadcastListResponse",
"etag": "\"I_8xdZu766_FSaexEaDXTIfEWc0/5WQLBG6RLCbLPgwsAs3o13sBM98\"",
"pageInfo": {
"totalResults": 0,
"resultsPerPage": 5
},
"items": [
{
"kind": "youtube#liveBroadcast",
"etag": "\"I_8xdZu766_FSaexEaDXTIfEWc0/vyGp6PvFo4RvsFtPoIWeCReyIC8\""
}
]
}
Only after go to live dashboard page stream now I can got default livebroadcast with broadcast type persistent and then got livestream by default livebroadcast boundStremId
Why? How I can get default livebroadcast and default livestream without go to livestream dashboard?

I tried your query, and just like you, I can get 200 response, but I can only get 1 result. So the alternative way that I used to get the live broadcast is by using the Search: list under the DATA API. Here, you can use the eventType=live to get the live broadcast video.
GET https://www.googleapis.com/youtube/v3/search?part=snippet&eventType=live&type=video&key={YOUR_API_KEY}
For the persistent broadcast, try to check this SO question if it can help you.
For more information check these related SO questions:
YouTube API live broadcast
How to get list of live video broadcasts using youtube api v3

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 do I get youtube shorts from youtube api data v3

I want a way to get YouTube shorts for a specific channel from YouTube API. I looked every where and I couldn't find anything.
Currently I can get a playlist ID for all channel videos with this endpoint:
request = youtube.channels().list(
part="contentDetails",
id=id
)
I also tried these parameters:
request = youtube.channels().list(
part="snippet,contentDetails,statistics,brandingSettings",
id=id
)
So is there a way to get YouTube shorts from a specific channel from YouTube API or any other source if it's available.
One way of detecting if a YouTube video ID is a Short without even using the API is to try a HEAD HTTP request to the /shorts/ version of the URL and see if it redirects you.
https://www.youtube.com/shorts/hKwrn5-7FjQ is a Short and if you visit that URL, you'll get an HTTP status code of 200 and the URL won't change.
https://www.youtube.com/watch?v=B-s71n0dHUk is not a Short, and if you visit https://www.youtube.com/shorts/B-s71n0dHUk, you get a 303 redirect back to the original URL.
Keep in mind, that this behavior might change down the line, but it works as of May 2022.
It seems that once again YouTube Data API v3 doesn't provide a basic feature.
For checking if a given video is a short:
I would recommend you to use my open-source YouTube operational API. Indeed by requesting the JSON document https://yt.lemnoslife.com/videos?part=short&id=VIDEO_ID containing item["short"]["available"] boolean, your problem is solved.
Example of short id: ydPkyvWtmg4
For listing shorts of a channel:
I would recommend you to use my open-source YouTube operational API. Indeed by requesting the JSON document https://yt.lemnoslife.com/channels?part=shorts&id=CHANNEL_ID. The entry item["shorts"] contains the data you are looking for. Note that the pagination works as the one of YouTube Data API v3.
Example of result for channel UC5O114-PQNYkurlTg6hekZw:
{
"kind": "youtube#channelListResponse",
"etag": "NotImplemented",
"items": [
{
"kind": "youtube#channel",
"etag": "NotImplemented",
"id": "UC5O114-PQNYkurlTg6hekZw",
"shorts": [
{
"videoId": "fP8nKVauFwc",
"title": "India: United Nations Counter Terrorism Committee Watch LIVE #shorts",
"thumbnails": [
{
"url": "https:\/\/i.ytimg.com\/vi\/fP8nKVauFwc\/hq720_2.jpg?sqp=-oaymwEYCNAFENAFSFryq4qpAwoIARUAAIhC0AEB&rs=AOn4CLCgJEYgv_msT5pkfWeEEN3VBt4wjg",
"width": 720,
"height": 720
}
],
"viewCount": 3700
},
...
],
"nextPageToken": "4qmFsgLlARIYVUM1TzExNC1QUU5Za3VybFRnNmhla1p3GsgBOGdhU0FScVBBVktNQVFxSEFRcGZRME00VVVGU2IyWnZaMWxqUTJob1ZsRjZWbEJOVkVVd1RGWkNVbFJzYkhKa1dFcHpWa2RqTW1GSFZuSlhibU5SUVZOSlVrTm5PSGhQYWtVeVRtcGplVTE2VlRST2FrVXdUbXBCY1VSUmIweFhWRUl5VGtab1dGSllSbGRNVmtVU0pEWXpOakJoTkRVNUxUQXdNREF0TWpKaE15MDRObUV6TFdRMFpqVTBOMlZqWVRSbFl4Z0I=,CgtuNjFmZlJlR0QxcyiVgICbBg=="
}
]
}
Below is a sample python code to send the HEAD HTTP request.
import requests
def is_short(vid):
url = 'https://www.youtube.com/shorts/' + vid
ret = requests.head(url)
if ret.status_code == 200:
return True
else: # whether 303 or other values, it's not short
return False
I don't know why but I don't get status code 303 whether it's a short or not with axios. So this is another way of checking if it's a short or not.
const isShort = async (videoId) => {
const url = "https://www.youtube.com/shorts/" + videoId
const res = await axios.head(url)
console.log(res.request.res.responseUrl)
// if it's a short it ends with "/shorts/videoId"
// if it's NOT a short it ends "/watch?=videoId"
}
Maybe axios automatically redirects?
You can use the new dimension called 'creatorContentType' from Youtube Analytics and Reports API.
// You can get IDs from PlaylistItems or Search API
const IDs = ["videoID1", "videoID2", "videoID3"];
// Get the analytics data of selected videos based on their IDs
const { data: analyticsData } = await youtubeAnalytics.reports.query({
ids: "channel==MINE",
startDate: "2019-01-01",
// Today's date
endDate: new Date().toISOString().split("T")[0],
metrics: "views",
dimensions: "video,creatorContentType",
filters: `video==${IDs.join(",")}`,
access_token,
});
It basically returns values listed below:
Value
Description
LIVE_STREAM
The viewed content was a YouTube live stream.
SHORTS
The viewed content was a YouTube Short.
STORY
The viewed content was a YouTube Story.
VIDEO_ON_DEMAND
The viewed content was a YouTube video that does not fall under one of the other dimension values.
UNSPECIFIED
The content type of the viewed content is unknown.
Notes:
Don't forget it returns values just for the videos uploaded after 01.01.2019.
Don't forget to add analytics scopes and enable Analytics and Reports API.

How to get any Youtube channel's subscribed users list and their details using YouTube Analytics API?

I am trying to get any youtube channel's subscribed users list and their detail(analysis), like the XYZ channel has 45% male users subscriber and 55% female users subscriber, this channel was subscribed by this top 5 countries subscriber and the channel Audience Demography related information.
For this, I use YouTube Analytics API v3 and my URL is like
https://www.googleapis.com/youtube/v3/subscriptions?part=snippet,contentDetails,subscriberSnippet&key=APIKEY&id=CHANNELID
but this URL return below code in response
{
{
"kind": "youtube#SubscriptionListResponse",
"etag": "TOmVRCZpu2meG82Dv9k7Y-QQ8t888",
"pageInfo": {
"totalResults": 0,
"resultsPerPage": 5
},
"items": []
}
I don't know I'm right or wrong for the use of this URL for getting the above detail. I did read all the questions about youtube data API but I did not find my question's answer on those questions.
Thanks in advance.
According to the docs, if your intention is to obtain subscriptions info w.r.t. a given channel -- identified by its channel ID --, then you should use the parameter channelId:
channelId (string)
The channelId parameter specifies a YouTube channel ID. The API will only return that channel's subscriptions.
Therefore, do change your URL above to:
https://www.googleapis.com/youtube/v3/subscriptions?part=snippet,contentDetails,subscriberSnippet&key=APIKEY&channelId=CHANNELID.
The kind of data you are requesting falls under the private data of a channel. You can only access such data if you are the owner of that channel (by authorizing - Oauth2) or if the channel owner lets you access that data (after going through authorization) through a publicly available application.

YouTube Data API channels list returning no results for valid Channel ID

I'm attempting to access https://www.youtube.com/channel/UC7LoiySz7-FcGgZCKBq_2vQ via the YouTube Data API v3 however am not able to load channel by id:
https://content.googleapis.com/youtube/v3/channels?part=snippet&id=UC7LoiySz7-FcGgZCKBq_2vQ&key=<omitted>
{
"kind": "youtube#channelListResponse",
"etag": "\"XI7nbFXulYBIpL0ayR_gDh3eu1k/Rk41fm-2TD0VG1yv0-bkUvcBi9s\"",
"pageInfo": {
"totalResults": 0,
"resultsPerPage": 0
},
"items": []
}
other channels that this same error occurs for:
https://www.youtube.com/channel/UCzwNZaQ2qyZw0n3xOSNoXaQ
https://www.youtube.com/channel/UC0iFwqagVPP6pXiDwYU170g
Your channels are of type hidden. This is the expected outcome. Unhide it and work your way from there.
Delete or hide your YouTube channel:
You can hide content from your YouTube channel and choose to re-enable
it later. When you hide content, your channel name, videos, likes,
subscriptions, and subscribers will be made private.
All your comments and replies will be permanently deleted. Your
account data on other Google properties will not be removed.
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=status&id=CHANNEL_ID, you will get the YouTube channel status message you are looking for in item["status"].
For instance with this channel id UC7LoiySz7-FcGgZCKBq_2vQ you would get:
{
"kind": "youtube#channelListResponse",
"etag": "NotImplemented",
"items": [
{
"kind": "youtube#channel",
"etag": "NotImplemented",
"id": "UC7LoiySz7-FcGgZCKBq_2vQ",
"status": "This channel is not available."
}
]
}
For a suspended YouTube channel such as UCF_UozwQBJY4WHZ7yilYkjA, you would get for status: "This account has been terminated due to multiple or severe violations of YouTube's policy on nudity or sexual content.".
For a normal channel, such as UC4QobU6STFB0P71PMvOGN5A, you would get for status: null.

Youtube Data API v3 playlistitems endpoint returning empty items array

I'm using the playlistItems endpoint to get a list of videos that have been uploaded by an account. The response shows 1 as totalResults, which is expected, but the items array is empty, which is not. It's not clear to me what's going on, since the video is public and has views on it.
I'm not seeing this issue pulling uploads from other accounts, so I'm wondering if it's a caching issue on the YT side, or some setting we need to enable on our account? I'm not able to find any documentation that would explain what's happening here.
The endpoint I'm hitting is https://www.googleapis.com/youtube/v3/playlistItems?key=<api key>&playlistId=UUjQYaIbYceXNNdC63dQ9aTg&maxResults=10&part=snippet, and the full response I'm receiving is:
{
"kind": "youtube#playlistItemListResponse",
"etag": "\"PSjn-HSKiX6orvNhGZvglLI2lvk/eJKYM5x3WquVgzqxNc7NMRuOS4o\"",
"pageInfo": {
"totalResults": 1,
"resultsPerPage": 10
},
"items": []
}
The item is now showing up, so it looks to just take some time before the API reflects what's been uploaded.

Resources