How to get all message from a youtube live stream - youtube-api

I want the get all the message from a youtube live stream. Even the once that are held back for review. Is this possible?
I made a request to https://www.googleapis.com/youtube/v3/liveChat/messages but i do not get the messages back that are held back for review. I would like the ability to get those messages and allow or deny them.

Related

Does the YouTube API have a webhook or a socket? Notify me when there is a new comment? [cerrada]

I have developed a program with the youtube api that get all the live chat (Message in live of youtube)
Now, I am looking for that every time there is a new message in the live chat,
This is because I want to create a bot so that when someone puts "Twitter!" the bot responds with my twitter.
Since I couldn't find a stream of the new messages, what I did was get the messages. And then get them back in 10 seconds. And then select the messages that you had not obtained before

List channel messages API does not list all messages

It seems list channel messages API does not lists all messages, specifically it does not list messages which are automatically posted when "Meet" button is pressed. When "Meet" button is pressed, it starts meetings, thus users can reply to the thread. We would like to find a way to capture such information using Graph APIs
Such messages are not returned by Graph API:
Conversations/replies to “Meet Now”(channel meeting) aren’t considered as channel messages since, user isn’t posting a message to channel. If the user is posting a new message to channel using “New Conversation Button” it’s considered as channel message.
Now, chat message API works because there is scope of chat replies for that particular message as a result we are also getting the replies back.
These features discussed above are by design.

Embed a YouTube channel's current live stream without the video ID

Every time a user starts a live stream on YouTube, a new ID is generated for the stream, along with the corresponding video and URL. Currently, if I want to embed a live stream, I can use YouTube's sharing functions to add the video to my page in an iFrame.
When the user stops streaming, embeds of the live stream automatically switch to showing a recording of that stream. However, if the user starts broadcasting again later on, the embed will continue to show the old recording instead of switching to the new stream. This is because the video ID in the embed is hard-coded and each stream generates a new video ID.
My goal is to create an embed that will automatically display a user's live stream whenever they are streaming, and show an indication of whether they're online or offline. Is there an embed URL that would allow me to do this, or is there something in the API that might help?
I want to embed other streams that aren't just my own, so I need to do this in a way that doesn't require the streamer to log in or authenticate on my site.
If you know the ID of a YouTube channel, and if that channel streams a livestream set to Public, an iframe with this URL will show it:
https://www.youtube.com/embed/live_stream?channel=YOUR_CHANNEL_ID_HERE
See https://stackoverflow.com/a/39582176/470749
Unfortunately I haven't found a similarly simple way to permanently embed the YouTube chat for that livestream.
As far as I can tell, there's nothing built into the YouTube API that would allow you to embed a channel's current live stream automatically without knowing its ID. That said, it's possible to implement this yourself by writing a custom API and hosting it on your own server.
I recognize that this can look like a daunting task, so I've laid out some rough steps below to get you started.
Set up an endpoint on your own server. You could accept a
channelId argument or hard-code one, depending on how extensible
you want this to be.
Query YouTube's search endpoint1 for the specified channelId and eventType=live. An HTTPS request for this will look something like this:https://www.googleapis.com/youtube/v3/search?part=snippet&channelId=[CHANNEL_ID]&eventType=live&maxResults=1&order=date&type=video&key=[YOUR_API_KEY]
Check the search JSON response. If it returns any results (data.pageInfo.totalResults > 0), you know that the channel is live.
If the channel is live, redirect the request to your server directly to the live video's embed URL based on the video's ID in the query response (data.items[0].id.videoId).
If the channel isn't live, create a placeholder as you see fit, or make a second request to search for eventType=completed for past broadcasts, eventType=upcoming for scheduled broadcasts, or remove the eventType parameter to get the most recent video.
Once you have a server that can respond and redirect requests, you can embed an iFrame in your page that points directly to your API URL. Your server will handle the logic and, using the redirect, change the iFrame to a YouTube video player automatically, without requiring you to perform client-side logic or expose your API key2.
1 As with all YouTube API requests, search#list queries will count towards your daily quota. If you intend for this to be a high-traffic endpoint, you could either request an increased quota from YouTube, or implement a caching solution on your end to cut down on the number of requests you make.
2 GCP (Google Cloud Platform), which you'll use to manage your access the YouTube Data API, has pretty good protections against API key theft for times when you do have to expose it on the client side. That being said, best practice is to keep your key secret by storing it only on the server whenever possible.

Youtube API - How to send direct messages to followers?

According to google support:
Use Messages to send private messages to other members of the YouTube
community. [...] The messages system utilizes Google+
messaging so your channel must be connected with a Google+ in order to
use this feature.
https://support.google.com/youtube/answer/57955?hl=en
Is it possible to send direct messages to followers via youtube or google plus API?
I think the closest thing that's currently implemented is the Subscriptions resource, which
"contains information about a YouTube user subscription. A
subscription notifies a user when new videos are added to a channel or
when another user takes one of several actions on YouTube, such as
uploading a video, rating a video, or commenting on a video." [source]
So your subscribers should be getting a notification when you upload a video or do something similar anyways. If you wanted to message each of them directly, I suppose you could use Subscriptions.list() with mySubscribers to get your list of subscribers, but I don't think there's a way to mass message them programmatically (seems like it could be easily abused).

How can I get the status of a user's stream?

I'm building a thing that tells people when a YouTube stream goes live. In order to build this, I need to know when a stream goes live, be it via push notification, polling, or some other method.
With Twitch, it's dead easy. All you have to do is send a GET to https://api.twitch.tv/kraken/streams/[STREAMER_USERNAME_HERE] and you get a JSON object with everything you'd ever hope to know (try it in your browser, it's great). I have combed through the YouTube Streaming and Data API's and nothing even close to this feature seems to exist.
I know that something, somewhere is alerting something when a stream goes live, because my phone gets a notification when the people I am subscribed to start streaming. But if there are no public calls in the API, I'm left with no other option than scraping the HTML off a page every couple seconds, which is bad for both me and YouTube.
Further on this, YouTube's push notification API for regular videos famously doesn't work [1] [2] [3] [4], and every dev is left to either use the deprecated XML feeds (which update sometimes up to an hour slow) or scrape HTML off youtube.com pages (the only current solution for instant updates). So, even if there's something off the API that I missed, it's moot if it doesn't actually work.
That said, am I missing something? Is it possible to get a notification if a stream goes live? It's kind of a deal-breaker for YouTube vs Twitch if there isn't.
It is currently not possible to do what you are asking with the public YouTube API.
You can only retrieve information about your own liveStream or liveBroadcast objects, not anyone else's. Additionally, there is no public API to get a notification when another user goes live.

Resources