Reputation: 384
I have been looking into getting messages from my live stream on youtube. I have a need to be able to process the chat in real time howver I have come to find a few issues.
For starter and the main issue really is that the order in which the chat comes through seems to be oldest first. This is rather a problem as if I am trying to handle new chat messages in real time, as the stream goes on the new messages go further and further down the list.
I must get next page keys which is a nightmare are the smallest page size i can requst from the api is 200 messages.
Its making the load a lot more that it needs to be.
Does anyone know how i might request the chat messages newest first or better handle the chat stream?
Im using PHP to read the API and I can read the messages into a database but i still have to go deeper and deeper as the chat goes on rather than just pull the new ones off the top.
Upvotes: 6
Views: 8228
Reputation: 381
You should be saving the last nextPageToken
response you get from calling the list endpoint. This way, you can call the endpoint with the pageToken
, getting only the new messages from the last time you queried the API.
Reference: https://developers.google.com/youtube/v3/live/docs/liveChatMessages/list
Upvotes: 5