Reputation: 826
I'm using the youtube data api v3 via the javascript library. The list livebroadcasts call (https://developers.google.com/youtube/v3/live/docs/liveBroadcasts/list) gets broadcasts owned by the currently authenticated user (eg a user authenticated by oauth). I want to get a broadcast for a given channelid and then get its livechatid.
Is it possible to get the livechatid of a live broadcast not owned by the current authed user?
In my web app if there's a live broadcast for a given hardcoded channel id then I'll let people watch the broadcast via the embedded player and interact via a chat widget. This allows users to follow along with instruction while using the web app, and interact via chat.
Some initial investigation:
In the docs there're no parameters available to get around this problem in order to retrieve a livebroadcast's livechatid, which is required to list and insert on the livechatmessages resource. You can use the search api resource to get the video id of the currently live broadcast (see How to check if YouTube channel is streaming live), but then you cannot use the id
request parameter of the list livebroadcast
request to get to the livechatid).
It is possible to use the livechatmessages resource for a livechatid that is not owned by the current authed user (tried this by getting hold of the livechatid as the owner account, then authing as a second account and using the api explorer). So once I get the livechatid I can do what's needed
I could use a server-side call to get hold of the current livechatid. That seems like the only good answer at this point, but is a bunch of extra work.
There's also the possibility to embed the youtube chat iframe (see https://support.google.com/youtube/answer/2524549), but it appears that if you're not signed in then the chat frame will redirect the parent and not return to the site after sign in. Perhaps I can use the google client api to sign in, then load the iframe. This would be easier on front end work but sacrifices any customisability.
Upvotes: 0
Views: 269
Reputation: 826
Answering despite not addressing the central question, because I couldn't see any way to get the livechatid for another user.
As in comment:
Using the client api to do oath before creating a chat iframe works fine. The chat iframe then loads and operates without any issues
One caveat to "without any issues" is that if I am signed in to youtube with account A (eg to broadcast) and then in the same browser (chrome, not incognito) use my app then the google api client can claim that I'm not signed in, which is fine, but when I then select an account B during oauth sign in then the resulting iframed chat uses account A instead of account B. This makes some sense, since in the context of my app I never signed in via the google api with my app api key, but in the context of the youtube chat iframe I could be A or B, presumably. And using another browser this problem doesn't occur; there's only one account in play.
Upvotes: 1