首页 > 解决方案 > 如何从 YouTube 实时获取订阅信息

问题描述

我不知道某些 YouTube 频道如何获得即时订阅者每当您使用此脚本时,您都会得到一个固定的计数器,例如 15K 15000 静态出现,并且在 16000 频道到达之前,数字不会像 15001 那样瞬间移动

来自使用此功能的 YouTube 频道之一的图片

在此处输入图像描述

这是我使用的文件,但需要修改以从 YouTube API 获得更好的信息

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>YouTube API</title>
</head>
<body>
    YouTube Subscribers
    <div id="subCount"></div>

    <script>

    // Get Subscribers
    const youtubeKey = ' ADD YOUR KEY HERE';
    const youtubeUser = ' ADD YOUR USER ID HERE';
    const subCount = document.getElementById('subCount');

    let getSubscribers = () => {

        fetch(`https://www.googleapis.com/youtube/v3/channels?part=statistics&id=${youtubeUser}&key=${youtubeKey}`)
        .then(response => {
            return response.json()
        })
        .then(data => {
            console.log(data);
            subCount.innerHTML = data["items"][0].statistics.subscriberCount;
        })

    }

    getSubscribers();

    </script>
</body>
</html>

标签: youtubeyoutube-apiyoutube-data-apiyoutube-livestreaming-api

解决方案


推荐阅读