获取youtube实时聊天评论和实时流“找不到您尝试检索的实时聊天[404]”和“未选择过滤器[400]”

时间:2019-10-01 19:31:14

标签: c# .net google-api youtube youtube-api

我需要使用Youtube API从我的youtube帐户中获取实时流列表,并从我的LiveStream LiveChat中获取所有评论。

该令牌很好(因为我多次删除了该令牌,并且在我再次启动该应用并获得许可后再次自动下载了该令牌)。 授予,删除和再次授予访问权限(我尝试过...)(我在这里可以通过“ youtube”权限https://myaccount.google.com/permissions?pli=1看到它) 在Google提示再次询问是否允许我访问此应用后,令牌已删除并自动再次自动添加。

LiveChatMessages.List错误

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错误

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

    }
}

0 个答案:

没有答案