Dear Developer Community,
I need some information. I want to get data when I am starting a live stream. what is the time it is started,
How many viewers are watching now, what total stream duration, and how many hours were watched?
You will need to periodically poll the Get Streams endpoint to get that data.
When the stream is live it’ll return a stream object, including the started_at timestamp, which along with the API no longer returning data indicating the stream is offline will allow you to calculate duration. Additionally, each time you poll the endpoint you can store the viewer_count at that time, from which you’ll also be able to calculate hours watched.
How frequently you poll the endpoint is up to you, keep in mind that it’s cached though so requesting it faster than once a minute is a waste, and can result in erroneous results if polled excessively fast. It’s not uncommon for stats tracking apps to poll between 1 and 15 minutes depending on needs.