private IEnumerator GetChannelDetails()
        {
            string channelDetailsURI = APIData.ChannelDetailsURI();

            if (Debug.isDebugBuild)
            {
#if UNITY_EDITOR
                if (showDebugLog)
                {
                    Debug.Log(channelDetailsURI);
                }
#elif UNITY_STANDALONE
                Debug.Log(channelDetailsURI);
#endif
            }
            UnityWebRequest webRequest = UnityWebRequest.Get(channelDetailsURI);
            yield return(webRequest.SendWebRequest());

            if (webRequest.isHttpError || webRequest.isNetworkError)
            {
                Debug.LogError(webRequest.error);
            }
            else
            {
                string jsonText = webRequest.downloadHandler.text;
                Json.ChannelDetails.SerializedItems serializedItems = JsonUtility.FromJson <Json.ChannelDetails.SerializedItems> (jsonText);
                SetChannelDetails(serializedItems);
                if (isFirstTry)
                {
                    StartCoroutine(GetChatId());
                }
                currentChannelCoroutine = StartCoroutine(WaitForReceiveChannelDetails());
            }
            webRequest.Dispose();
        }
        private IEnumerator GetChatId()
        {
            string searchChatURI = APIData.SearchChatURI();

            if (Debug.isDebugBuild)
            {
#if UNITY_EDITOR
                if (showDebugLog)
                {
                    Debug.Log(searchChatURI);
                }
#elif UNITY_STANDALONE
                Debug.Log(searchChatURI);
#endif
            }
            UnityWebRequest webRequest = UnityWebRequest.Get(searchChatURI);
            yield return(webRequest.SendWebRequest());

            if (webRequest.isHttpError || webRequest.isNetworkError)
            {
                Debug.Log(webRequest.error);
            }
            else
            {
                string jsonText = webRequest.downloadHandler.text;
                Json.LiveStreamingDetails.SerializedItems serializedItems = JsonUtility.FromJson <Json.LiveStreamingDetails.SerializedItems> (jsonText);
                if (serializedItems.items[0].liveStreamingDetails.activeLiveChatId == null)
                {
                    Debug.LogError("this broadcast is not started yet or already closed.");
                }
                else
                {
                    SetLiveStreamingDetails(serializedItems);
                    SetChatId(serializedItems);
                    currentChatCoroutine = StartCoroutine(GetChat());
                }
            }
            webRequest.Dispose();
        }
        private IEnumerator GetVideoId()
        {
            string videoSearchURI = APIData.SearchVideoURI();

            if (Debug.isDebugBuild)
            {
#if UNITY_EDITOR
                if (showDebugLog)
                {
                    Debug.Log(videoSearchURI);
                }
#elif UNITY_STANDALONE
                Debug.Log(videoSearchURI);
#endif
            }
            UnityWebRequest webRequest = UnityWebRequest.Get(videoSearchURI);
            yield return(webRequest.SendWebRequest());

            if (webRequest.isHttpError || webRequest.isNetworkError)
            {
                Debug.LogError(webRequest.error);
            }
            else
            {
                string jsonText = webRequest.downloadHandler.text;
                Json.LiveStreamingDetails.SerializedItems serializedItems = JsonUtility.FromJson <Json.LiveStreamingDetails.SerializedItems> (jsonText);
                if (serializedItems.items.Length != 0)
                {
                    SetVideoId(serializedItems);
                    StartCoroutine(GetVideoDetails());
                }
                else
                {
                    Debug.LogWarning("there is no any active broadcast");
                }
            }
            webRequest.Dispose();
        }
        private IEnumerator GetChat()
        {
            if (APIData.chatId.Equals(""))
            {
                yield break;
            }
            if (!receiveChat)
            {
                Debug.Log("receive chat stopped");
                yield break;
            }
            float waitSeconds = (float)TimeSpan.FromMilliseconds(pollingIntervalMillis).TotalSeconds;

            yield return(new WaitForSeconds(waitSeconds));

            pollingIntervalMillis = 0;
            string chatURI = APIData.ChatURI();

            if (Debug.isDebugBuild)
            {
#if UNITY_EDITOR
                if (showDebugLog)
                {
                    Debug.Log(chatURI);
                }
#elif UNITY_STANDALONE
                Debug.Log(chatURI);
#endif
            }
            UnityWebRequest webRequest = UnityWebRequest.Get(chatURI);
            yield return(webRequest.SendWebRequest());

            string jsonText = webRequest.downloadHandler.text;
            Json.ChatDetails.SerializedItems serializedItems = JsonUtility.FromJson <Json.ChatDetails.SerializedItems> (jsonText);
            if (serializedItems.items != null)
            {
                if (serializedItems.items.Length == 0)
                {
                    noItemsRespondCount++;
                    if (noItemsRespondCount >= noItemsRespondLimit)
                    {
                        noItemsRespondCount   = 0;
                        currentCheckCoroutine = StartCoroutine(GetVideoDetails());
                    }
                }
                else
                {
                    SetNextPageToken(serializedItems);
                    pollingIntervalMillis = serializedItems.pollingIntervalMillis;
                    AddComment(serializedItems);
                }
            }

            /* else if (serializedItems.error != null) {
             *             ErrorDetails details = ErrorMessageResolver.FormatError (serializedItems.error);
             *             if (details.reason.Equals (ErrorMessageResolver.Reason.liveChatEnded.ToString ())) {
             *                 Debug.Log ("LiveChatが終了したため、コメントの取得を停止しました。");
             *                 ClearSettings ();
             *                 yield break;
             *             }
             *         } */
            if (serializedItems.pollingIntervalMillis < defaultPollingIntervalMillis)
            {
                pollingIntervalMillis = defaultPollingIntervalMillis;
            }
            webRequest.Dispose();
            if (liveStatus.liveBroadcastContent.Equals("none"))
            {
                StopReceiveProgress();
                Debug.Log("Liveが終了しているため、コメントの取得を停止しました。");
                yield break;
            }
            currentChatCoroutine = StartCoroutine(WaitForReceiveChat());
        }
 /// <summary>
 /// コメント取得を停止し、チャンネルIDやビデオIDを消します。APIKeyは保持されます。
 /// </summary>
 public void ClearSettings()
 {
     StopReceiveProgress();
     APIData.InitializeData();
     isFirstTry = true;
 }