Created
March 9, 2022 21:42
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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