Skip to content

Instantly share code, notes, and snippets.

@toshvelaga
Created March 9, 2022 21:42
Show Gist options
  • Select an option

  • Save toshvelaga/0249357ceee6afee3287ad09335aebd1 to your computer and use it in GitHub Desktop.

Select an option

Save toshvelaga/0249357ceee6afee3287ad09335aebd1 to your computer and use it in GitHub Desktop.
counts the youtube live view count using the google api on the client
const youtubeLiveViewCount = () => {
// https://developers.google.com/youtube/v3/docs/videos/list?apix=true#parameters
return gapi.client.youtube.videos
.list({
part: ['statistics'],
id: youtubeBroadcastId,
})
.then(
function (res) {
// Handle the results here (response.result has the parsed body).
let youtubeViews = res.result.items[0].statistics.viewCount
console.log('Response', youtubeViews)
setyoutubeViewCount(youtubeViews)
},
function (err) {
console.error('Execute error', err)
}
)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment