Retrieve public statistics of video via youtube api

后端 未结 3 870
执念已碎
执念已碎 2021-01-14 16:42

It\'s possible to obtain public statistics of video?

Using something like this i can get just total views of video and like count:

https://www.google         


        
3条回答
  •  陌清茗
    陌清茗 (楼主)
    2021-01-14 17:06

    You would need to create YouTubeService object and can get search results for the keywords

    YouTubeService youtubeService = new YouTubeService(new BaseClientService.Initializer()
    {
      ApiKey = "dfhdufhdfahfujashfd",
      ApplicationName = this.GetType().ToString()
    });
    
     var searchListRequest = youtubeService.Search.List("snippet");
          searchListRequest.Q = "cute cats"; 
          searchListRequest.MaxResults = 10;
    
      var searchListResponse = await searchListRequest.ExecuteAsync();
      var videoId = searchListResponse.Items.First().Id.VideoId is the unique id of the video
    
    // Video Request    
    VideosResource.ListRequest request = new VideosResource.ListRequest(youTubeService, "statistics")
    {
      Id = videoId
    };
    
    VideoListResponse response = request.Execute();
    if (response.Items.First() != null && response.Items.First().Statistics != null)
    {
      Console.WriteLine(response.Items.First().Statistics.ViewCount);
    }
    

提交回复
热议问题