我已按照this Google video及其他地方的说明进行操作:
前两个阶段有效,我可以获取频道/播放列表ID,但playlistItems
每次都会返回playlistNotFound
(我已经使用多个不同的YouTube帐户对其进行了测试。)< / p>
我一直在努力仔细检查拼写错误 - 我无法发现任何错误的请求。
任何想法,或任何人都能重现这个问题?
示例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"
}
]
}
尝试获取播放列表中的第一个视频:
{
"error": {
"errors": [
{
"domain": "youtube.playlistItem",
"reason": "playlistNotFound",
"message": "Not Found",
"locationType": "parameter",
"location": "playlistId"
}
],
"code": 404,
"message": "Not Found"
}
}
注意:我生成了一个服务器键,因为它将在服务器上运行。但我正在浏览器中测试(IP地址列入白名单。)这不应该导致任何问题吗? (到目前为止没有auth错误。)
答案 0 :(得分:3)
威廉, 你用作播放列表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"
}
}]
}