如何在当前直播流中仅获得SuperChat Event

时间:2019-07-26 17:34:11

标签: c# unity3d youtube-livestreaming-api

我想通过Youtube Livestream API获得超级聊天事件。

我已经尝试使用LiveChatMessages获得超级聊天事件。

// before this script, pass the OAuth and get the LiveChat ID from video ID
            url = "https://www.googleapis.com/youtube/v3/liveChat/messages?part=snippet,authorDetails";
            url += "&liveChatId=" + id;

            req = UnityWebRequest.Get(url);
            req.SetRequestHeader("Authorization", "Bearer " + token);
            yield return req.SendWebRequest();
            Debug.Log("Comment");
            Debug.Log(req.downloadHandler.text);

            //parse comment 
            var comments = JsonUtility.FromJson<Comments>(req.downloadHandler.text);
            var items = comments.items;
            pageToken = comments.nextPageToken;
            foreach (var item in items)
            {
                try
                {
                    if (item.snippet.superChatDetails != null)
                    {
                        var snip = item.snippet;
                        var author = item.authorDetails;
                        Debug.Log(author.displayName + ": " + snip.displayMessage);
                    }
                    else
                    {
                        Debug.Log(item.authorDetails.displayName + ": " + item.snippet.superChatDetails.userComment + "/ amount : " + item.snippet.superChatDetails.amountMicros);
                    }
                }
                catch (Exception f) {
                    //nothing to do
                }
            }
// after the script select the superchat event using "var comments"

在此脚本中,它可以获取superChat事件。但是API查询很快就会受到限制(API保持20分钟,间隔为1.0秒)
我想减少API查询的使用,只是获得SuperChat事件

0 个答案:

没有答案