Harshit Laddha
Harshit Laddha

Reputation: 2124

Youtube Live chat messages Javascript API responses not synced with actual chat visible on youtube website and apps

We are trying to setup online streaming events through youtube (Video URL - https://www.youtube.com/watch?v=Sby6O2k9j4k) Now here when we scroll to the end we see one message in the live chat replay. But when I try to query the same with the API from here -

GET https://www.googleapis.com/youtube/v3/liveChat/messages

with params - liveChatId: Cg0KC2ZRcnpkRW5Vbm1J, part: id,snippet,authorDetails

I get a different message list which I tried inserting from this API -

POST https://www.googleapis.com/youtube/v3/liveChat/messages

with this request body -

{
  "snippet": {
    "liveChatId": "Cg0KC2ZRcnpkRW5Vbm1J",
    "type": "textMessageEvent",
    "textMessageDetails": {
      "messageText": "Test chat message api"
    }
  }
}

So, only this message which I sent through the insert API are coming back in the list API but not the ones that are posted through and visible on youtube website. Can anyone help out in debugging or fixing this.

Also, I tried to embed the iframe with the live chat but for some reason the iframe is not visible in mobile devices so If there is a fix for that it would make my life even more easier. TIA

Upvotes: 2

Views: 1532

Answers (1)

Maqsood Ahmed
Maqsood Ahmed

Reputation: 2257

It looks like you are getting messages from previous broadcast. Every time whenever you Go Live to YouTube a new broadcast object is created. So, first you need to get broadcasts list by providing parameter (broadcastStatus= active)

GET https://www.googleapis.com/youtube/v3/liveBroadcasts?part=[id,snippet,contentDetails,status]&broadcastStatus=active&key=[YOUR_API_KEY] HTTP/1.1

Authorization: Bearer [YOUR_ACCESS_TOKEN] Accept: application/json

In response there will be broadcasts list which are live now. So, there will be liveChatId. and you can get all messages for your current broadcast.

GET https://www.googleapis.com/youtube/v3/liveChat/messages?part=[id,snippet,contentDetails,status]&key=[YOUR_API_KEY] HTTP/1.1

Authorization: Bearer [YOUR_ACCESS_TOKEN] Accept: application/json

Please feel free to let me know if this does'nt work.

Ref: liveBroadcasts List and livechatMessages List

Upvotes: 1

Related Questions