【问题标题】:I am trying to use GoogleAPI YouTube to get details about YouTube Videos我正在尝试使用 GoogleAPI YouTube 获取有关 YouTube 视频的详细信息
【发布时间】:2015-08-23 12:29:10
【问题描述】:

使用 GoogleAPI v3 网址 使用这个网址: https://www.googleapis.com/youtube/v3/videos?part=snippet&id=D-wxnID2q4A&key={MyKey}

我得到了这个 json:

    {
 "kind": "youtube#videoListResponse",
 "etag": "\"dhbhlDw5j8dK10GxeV_UG6RSReM/uzqDS1yLcX0DglL60bHeS56kZ7c\"",
 "pageInfo": {
  "totalResults": 1,
  "resultsPerPage": 1
 },
 "items": [
  {
   "kind": "youtube#video",
   "etag": "\"dhbhlDw5j8dK10GxeV_UG6RSReM/l7OMkGqgmC10NvbO5PzI_nonZzA\"",
   "id": "D-wxnID2q4A",
   "snippet": {
    "publishedAt": "2014-01-08T05:34:04.000Z",
    "channelId": "UCtA7mzeypl_udtFySMXTusQ",
    "title": "Can You Walk on Water? (Non-Newtonian Fluid Pool)",
    "description": "Running, jumping and biking on 8,000 litres of non-newtonian fluid in Kuala Lumpur, Malaysia! Brought to you by Mach by Hong Leong Bank together with We are KIX. Music and info below..\n\nGet Banking with Mach by Hong Leong Bank: http://www.machbyhongleongbank.com\n\nA film and event concept by: http://www.wearekix.com\n\nFeatured Runner: https://www.caykuijpers.com\n\nMUSIC by Thrill me now & Ion Ray: https://soundcloud.com/thrillmenow/walk-on-water-canyouwalkonwater-soundtrack\n\nHosted at: The Square Publika \nDance Crew: http://www.facebook.com/KatoonNetworkDanceCrew\nLive DJ and Sound Effects by: http://www.facebook.com/weare2db\nLive DJ's: http://www.facebook.com/deersociety",
    "thumbnails": {
     "default": {
      "url": "https://i.ytimg.com/vi/D-wxnID2q4A/default.jpg",
      "width": 120,
      "height": 90
     },
     "medium": {
      "url": "https://i.ytimg.com/vi/D-wxnID2q4A/mqdefault.jpg",
      "width": 320,
      "height": 180
     },
     "high": {
      "url": "https://i.ytimg.com/vi/D-wxnID2q4A/hqdefault.jpg",
      "width": 480,
      "height": 360
     },
     "standard": {
      "url": "https://i.ytimg.com/vi/D-wxnID2q4A/sddefault.jpg",
      "width": 640,
      "height": 480
     },
     "maxres": {
      "url": "https://i.ytimg.com/vi/D-wxnID2q4A/maxresdefault.jpg",
      "width": 1280,
      "height": 720
     }
    },
    "channelTitle": "Mach by Hong Leong Bank",
    "categoryId": "24",
    "liveBroadcastContent": "none",
    "localized": {
     "title": "Can You Walk on Water? (Non-Newtonian Fluid Pool)",
     "description": "Running, jumping and biking on 8,000 litres of non-newtonian fluid in Kuala Lumpur, Malaysia! Brought to you by Mach by Hong Leong Bank together with We are KIX. Music and info below..\n\nGet Banking with Mach by Hong Leong Bank: http://www.machbyhongleongbank.com\n\nA film and event concept by: http://www.wearekix.com\n\nFeatured Runner: https://www.caykuijpers.com\n\nMUSIC by Thrill me now & Ion Ray: https://soundcloud.com/thrillmenow/walk-on-water-canyouwalkonwater-soundtrack\n\nHosted at: The Square Publika \nDance Crew: http://www.facebook.com/KatoonNetworkDanceCrew\nLive DJ and Sound Effects by: http://www.facebook.com/weare2db\nLive DJ's: http://www.facebook.com/deersociety"
    }
   }
  }
 ]
}

我正在为 YouTube 使用 C# (Nuget) GoogleAPI,我已授予 API 权限并收到了我的 v3 密钥。

我的 C# 代码是:

 var      VideoID = "D-wxnID2q4A";
 var youtubeService = new YouTubeService(new BaseClientService.Initializer()
            {
                ApiKey = APT.core.Properties.Settings.Default.GoogleKey,
                ApplicationName = this.GetType().ToString()
            });


            var t=  youtubeService.Videos.List("part=snippet,id="+VideoID);

这会引发异常:

Exception:Thrown: "Google.Apis.Requests.RequestError
No filter selected. [400]
Errors [
    Message[No filter selected.] Location[ - parameter] Reason[missingRequiredParameter] Domain[youtube.parameter]
]

我做错了什么?

【问题讨论】:

    标签: youtube-api youtube-data-api google-api-dotnet-client


    【解决方案1】:

    这样的事情应该可以工作:

        var VideoID = "D-wxnID2q4A";
        var youtubeService = new YouTubeService(new BaseClientService.Initializer()
        {
            ApiKey = "{YOUR-API-KEY}",
            ApplicationName = "YouTube-test"
        });
    
        var t = youtubeService.Videos.List("snippet");
        t.Id = VideoID;
        var listResponse = t.Execute();
    

    listResponse 应该包含您需要的信息。

    【讨论】:

      【解决方案2】:
        public List<VideoItem> GetCurrentChannelVideos()
          {
              var channelsListRequest = youtube.Channels.List("contentDetails");
              channelsListRequest.Mine = true;
              // Retrieve the contentDetails part of the channel resource for the authenticated user's channel.
              var channelsListResponse = channelsListRequest.Execute();
              //List<VideoLink> allVideos = new List<VideoLink>();
              List<VideoItem> allVideos = new List<VideoItem>();
              foreach (var channel in channelsListResponse.Items)
              {
                  // From the API response, extract the playlist ID that identifies the list
                  // of videos uploaded to the authenticated user's channel.
                  var uploadsListId = channel.ContentDetails.RelatedPlaylists.Uploads;
                  var nextPageToken = "";
                  while (nextPageToken != null)
                  {
                      var playlistItemsListRequest = youtube.PlaylistItems.List("snippet,status");
                      playlistItemsListRequest.PlaylistId = uploadsListId;
                      playlistItemsListRequest.MaxResults = 50;
                      playlistItemsListRequest.PageToken = nextPageToken;
      
                      // Retrieve the list of videos uploaded to the authenticated user's channel.
                      var playlistItemsListResponse = playlistItemsListRequest.Execute();
                      allVideos.AddRange(playlistItemsListResponse.Items.Select(s => new VideoItem() { VideoID = s.Snippet.ResourceId.VideoId, ThumbnailURL = s.Snippet.Thumbnails.Default__.Url, Title = s.Snippet.Title }).ToList());
                      nextPageToken = playlistItemsListResponse.NextPageToken;
      
                  }
              }
              return allVideos;
          }
      

      【讨论】:

      • 虽然此代码可能会回答问题,但提供有关此代码为何和/或如何回答问题的额外上下文可提高其长期价值。
      • @CarstenLøvboAndersen 请仔细查看。这篇文章不包含任何链接。
      猜你喜欢
      • 1970-01-01
      • 2014-04-20
      • 1970-01-01
      • 1970-01-01
      • 2019-03-08
      • 2014-10-10
      • 1970-01-01
      • 2016-05-23
      • 2015-02-23
      相关资源
      最近更新 更多