Получите комментарии и прямые трансляции в чате на YouTube: «Живой чат, который вы пытаетесь получить, не найден [404]» и «Фильтр не выбран [400]» - PullRequest
0 голосов
/ 01 октября 2019

Мне нужно получить список прямых трансляций из моей учетной записи YouTube и все комментарии из моей LiveStream LiveChat с помощью API-интерфейсов Youtube.

Токен хорош (потому что я удалял его много раз, и он автоматически снова загружался)когда я снова запустил приложение и получил разрешение). Доступ предоставлен, удален и предоставлен снова (я пытался ...) (я вижу его здесь с разрешением «youtube» https://myaccount.google.com/permissions?pli=1) Токен удален и автоматически добавлен снова после запроса Google, где меня снова спросили, даю ли ядоступ к этому приложению.

LiveChatMessages.List error

Google.GoogleApiException: 'Google.Apis.Requests.RequestError
The live chat that you are trying to retrieve cannot be found. Check the value of the requests <code>liveChatId</code> parameter to ensure that it is correct. [404]
Errors [
    Message[The live chat that you are trying to retrieve cannot be found. Check the value of the requests <code>liveChatId</code> parameter to ensure that it is correct.] Location[ - ] Reason[liveChatNotFound] Domain[youtube.liveChat]
]

LiveStreams.List error

Google.GoogleApiException: 'Google.Apis.Requests.RequestError
No filter selected. Expected one of: id, mine, idParam, default [400]
Errors [
    Message[No filter selected. Expected one of: id, mine, idParam, default] Location[ - parameter] Reason[missingRequiredParameter] Domain[youtube.parameter]
]
using Google.Apis.Auth.OAuth2;
using Google.Apis.Services;
using Google.Apis.Util.Store;
using Google.Apis.YouTube.v3;
using Google.Apis.YouTube.v3.Data;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace YoutubeManager
{
    public partial class form_main : Form
    {
        //variables
        public static Boolean google_init = false;
        public static string[] Scopes = { YouTubeService.Scope.Youtube };
        public static string ApplicationName = "myappYoutubeManager";
        public static UserCredential youtubeCredentials;
        public static YouTubeService youtubeService = new YouTubeService();

        public form_main()
        {
            InitializeComponent();
        }

        private void Btn_test_Click(object sender, EventArgs e)
        {
            //Authenticate (only once)
            googleAuthentication();

            //LiveChatMessageListResponse response = youtubeService.LiveChatMessages.List(liveChatId: "5SqXKq79WzM", part: "id").Execute();
            LiveStreamListResponse response = youtubeService.LiveStreams.List(part: "mine").Execute();
        }

        #region GoogleAuthentication
        private void googleAuthentication()
        {
            // INIT
            if (!google_init)
            {
                // Create credentials using the token.json
                using (var stream =
                    new FileStream("credentials.json", FileMode.Open, FileAccess.ReadWrite))
                {
                    // The file token.json stores the user's access and refresh tokens, and is created
                    // automatically when the authorization flow completes for the first time.
                    string credPath = "token.json";
                    youtubeCredentials = GoogleWebAuthorizationBroker.AuthorizeAsync(
                        GoogleClientSecrets.Load(stream).Secrets,
                        Scopes,
                        "myappYoutubeManagerUser",
                        CancellationToken.None,
                        new FileDataStore(credPath, true)).Result;
                    Console.WriteLine("Credential file saved to: " + credPath);
                }

                //Create Youtube API service
                youtubeService = new YouTubeService(new BaseClientService.Initializer()
                {
                    HttpClientInitializer = youtubeCredentials,
                    ApplicationName = ApplicationName,
                });


                // Set init true
                google_init = true;
            }
        }
        #endregion

    }
}
...