【问题标题】:YouTube Data API v3 - playlistItems returning playlistNotFoundYouTube 数据 API v3 - 返回 playlistNotFound 的播放列表项
【发布时间】:2015-06-30 17:55:32
【问题描述】:

我已按照this Google video 和其他地方的说明进行操作:

  • 使用静态 API 密钥连接到 v3 API
  • 使用旧频道 ID(例如“GoogleDevelopers”)获取频道上传的播放列表 ID
  • 使用该播放列表的 playlistItems 端点来检索上传到该 YouTube 帐户的视频列表。

前两个阶段有效,我能够获取频道/播放列表 ID,但 playlistItems 每次都返回 playlistNotFound(我已经使用多个不同的 YouTube 帐户对其进行了测试。)

我一直在仔细检查是否有错别字 - 我无法发现请求有任何问题。

有什么想法,或者任何人都可以重现这个问题吗?

示例 API 调用(使用他们视频中显示的 GoogleDevelopers 频道​​) - 您需要 generate your own API key 来测试:

https://www.googleapis.com/youtube/v3/channels?key=[myAPIkey]&forUsername=GoogleDevelopers&part=id

回复:

{
 "kind": "youtube#channelListResponse",
 "etag": "\"IHLB7Mi__JPvvG2zLQWAg8l36UU/9Uu_LJKSiIBlJOBZoZLkKcjhUUE\"",
 "pageInfo": {
  "totalResults": 1,
  "resultsPerPage": 5
 },
 "items": [
  {
   "kind": "youtube#channel",
   "etag": "\"IHLB7Mi__JPvvG2zLQWAg8l36UU/JgZIwrlCnsd1wzjssCxaCFp8mRU\"",
   "id": "UC_x5XG1OV2P6uZZ5FSM9Ttw"
  }
 ]
}

尝试获取播放列表中的第一个视频:

https://www.googleapis.com/youtube/v3/playlistItems?part=snippet&maxResults=1&key=[myAPIkey]&playlistId=UC_x5XG1OV2P6uZZ5FSM9Ttw

{
 "error": {
  "errors": [
   {
    "domain": "youtube.playlistItem",
    "reason": "playlistNotFound",
    "message": "Not Found",
    "locationType": "parameter",
    "location": "playlistId"
   }
  ],
  "code": 404,
  "message": "Not Found"
 }
}

注意:我生成了一个 server 密钥,因为它将在服务器上运行。但是我正在浏览器中进行测试(将 IP 地址列入白名单)。这应该不会引起任何问题吗? (到目前为止没有验证错误。)

【问题讨论】:

  • 嘿@William,即使我面临同样的问题。你能解决吗?
  • @Adithya no - 我最终做的是使用 RSS 提要:youtube.com/feeds/… - 我确实设法让 v3 数据 API 工作以检索特定的详细信息视频,格式为:googleapis.com/youtube/v3/…

标签: youtube youtube-data-api


【解决方案1】:

威廉, 您用作播放列表 id 的是频道 id,要获取具有 id 的播放列表列表,您需要将 contentDetails 添加到 part 参数。

https://www.googleapis.com/youtube/v3/channels?part=contentDetails&maxResults=50&forUsername=GoogleDevelopers&key=<APIKEY>

回复:

{
  kind: "youtube#channelListResponse",
  etag: ""iDqJ1j7zKs4x3o3ZsFlBOwgWAHU/rGUGLTaUoy_huV1Qfc0wvulpr7M"",
  pageInfo: {
    totalResults: 1,
    resultsPerPage: 50
  },
  items: [
    {
      kind: "youtube#channel",
      etag: ""iDqJ1j7zKs4x3o3ZsFlBOwgWAHU/Il2dF5SRdky6_tqanN3hNuDyfxc"",
      id: "UC_x5XG1OV2P6uZZ5FSM9Ttw",
      contentDetails: {
        relatedPlaylists: {
          uploads: "UU_x5XG1OV2P6uZZ5FSM9Ttw"
        },
      googlePlusUserId: "111395306401981598462"
      }
    }
  ]
}

然后使用“UU_x5XG1OV2P6uZZ5FSM9Ttw”作为上传播放列表,这样下一次调用将如下所示:

https://www.googleapis.com/youtube/v3/playlistItems?part=contentDetails&maxResults=1&playlistId=UU_x5XG1OV2P6uZZ5FSM9Ttw&key=<APIKEY>

回复:

{
  kind: "youtube#playlistItemListResponse",
  etag: ""iDqJ1j7zKs4x3o3ZsFlBOwgWAHU/AqAMzBB7CuVjpCKtQDHbbIvjtMU"",
  nextPageToken: "CAEQAA",
  pageInfo: {
    totalResults: 3761,
    resultsPerPage: 1
  },
  items: [{
    kind: "youtube#playlistItem",
    etag: ""iDqJ1j7zKs4x3o3ZsFlBOwgWAHU/qjqde7mm3USo4TmUrxDN8KdbyaQ"",
    id: "UUj6hVp42BfAXGn9SkmnI_HudylmOycmdp",
    contentDetails: {
      videoId: "tjmRUgUca1g"
    }
  }]
}

【讨论】:

    猜你喜欢
    • 2018-07-15
    • 2016-09-17
    • 2014-06-04
    • 2012-10-25
    • 2021-12-21
    • 2022-11-07
    • 2013-09-20
    • 2015-08-18
    • 2017-04-05
    相关资源
    最近更新 更多