Youtube API v3 data.search 返回相同的值
Youtube API v3 data.search returning same value
我试图在 regionCode
的基础上获取不同的 YouTube 频道。
正在尝试获取印度 YouTube 频道:
https://www.googleapis.com/youtube/v3/search?part=snippet&type=channel®ionCode=IN&maxResults=5&key={API_KEY}
正在尝试获取马来西亚 YouTube 频道:
https://www.googleapis.com/youtube/v3/search?part=snippet&type=channel®ionCode=MY&maxResults=5&key={API_KEY}
这两个请求的结果相同。为什么会这样?
{
"kind": "youtube#searchListResponse",
"etag": "\"iDqJ1j7zKs4x3o3ZsFlBOwgWAHU/EiqwT6pG1EkwVEl17s1_qudvkmk\"",
"nextPageToken": "CAUQAA",
"pageInfo": {
"totalResults": 1000000,
"resultsPerPage": 5
},
"items": [
{
"kind": "youtube#searchResult",
"etag": "\"iDqJ1j7zKs4x3o3ZsFlBOwgWAHU/smpwgLdS9Og11NhpzRYcy37a9V8\"",
"id": {
"kind": "youtube#channel",
"channelId": "UCrFiA0hztL9e8zTi_qBuW4w"
},
"snippet": {
"publishedAt": "2013-03-19T20:35:41.000Z",
"channelId": "UCrFiA0hztL9e8zTi_qBuW4w",
"title": "EeOneGuy",
"description": "Просто делаю ролики =)",
"thumbnails": {
"default": {
"url": "https://lh6.googleusercontent.com/-ZPtgaY_lFDY/AAAAAAAAAAI/AAAAAAAAAAA/U_8gJcnIMiE/photo.jpg"
},
"medium": {
"url": "https://lh6.googleusercontent.com/-ZPtgaY_lFDY/AAAAAAAAAAI/AAAAAAAAAAA/U_8gJcnIMiE/photo.jpg"
},
"high": {
"url": "https://lh6.googleusercontent.com/-ZPtgaY_lFDY/AAAAAAAAAAI/AAAAAAAAAAA/U_8gJcnIMiE/photo.jpg"
}
},
"channelTitle": "EeOneGuy",
"liveBroadcastContent": "none"
}
},
{
"kind": "youtube#searchResult",
"etag": "\"iDqJ1j7zKs4x3o3ZsFlBOwgWAHU/g4m9Kno2zbU7BMIEUbffxDlyvZI\"",
"id": {
"kind": "youtube#channel",
"channelId": "UC7MO7ngSqsBcvQvxNf-kpWg"
},
"snippet": {
"publishedAt": "2013-06-04T17:39:49.000Z",
"channelId": "UC7MO7ngSqsBcvQvxNf-kpWg",
"title": "The Right to Research Coalition",
"description": "The Right to Research Coalition is a coalition of 80 undergraduate and graduate student organisations from across the world. Together we educate and ...",
"thumbnails": {
"default": {
"url": "https://lh5.googleusercontent.com/-p0RT2XiO3_0/AAAAAAAAAAI/AAAAAAAAAAA/tdAJTswPnB0/photo.jpg"
},
"medium": {
"url": "https://lh5.googleusercontent.com/-p0RT2XiO3_0/AAAAAAAAAAI/AAAAAAAAAAA/tdAJTswPnB0/photo.jpg"
},
"high": {
"url": "https://lh5.googleusercontent.com/-p0RT2XiO3_0/AAAAAAAAAAI/AAAAAAAAAAA/tdAJTswPnB0/photo.jpg"
}
},
"channelTitle": "R2RCvideo",
"liveBroadcastContent": "none"
}
},
{
"kind": "youtube#searchResult",
"etag": "\"iDqJ1j7zKs4x3o3ZsFlBOwgWAHU/nWC7qhbPZRH0qyEBOcWdFR8TI5k\"",
"id": {
"kind": "youtube#channel",
"channelId": "UCmSSq5573Ru9asXsXykgqTw"
},
"snippet": {
"publishedAt": "2014-10-12T02:26:56.000Z",
"channelId": "UCmSSq5573Ru9asXsXykgqTw",
"title": "Toys Games TV",
"description": "Welcome to Toys Games TV Channel! Looking for a safe channel for your kids? Look no further, on TGTV we review primarily Disney, PBS & Sprout character ...",
"thumbnails": {
"default": {
"url": "https://lh3.googleusercontent.com/-5qqjMUWhRow/AAAAAAAAAAI/AAAAAAAAAAA/2la9IA5DNhU/photo.jpg"
},
"medium": {
"url": "https://lh3.googleusercontent.com/-5qqjMUWhRow/AAAAAAAAAAI/AAAAAAAAAAA/2la9IA5DNhU/photo.jpg"
},
"high": {
"url": "https://lh3.googleusercontent.com/-5qqjMUWhRow/AAAAAAAAAAI/AAAAAAAAAAA/2la9IA5DNhU/photo.jpg"
}
},
"channelTitle": "ToysGamesTV",
"liveBroadcastContent": "upcoming"
}
},
{
"kind": "youtube#searchResult",
"etag": "\"iDqJ1j7zKs4x3o3ZsFlBOwgWAHU/enqEI6qDr8UfYcjixI9Cjpd6SU0\"",
"id": {
"kind": "youtube#channel",
"channelId": "UCtjLPHCyI5V-xuumAXzAizA"
},
"snippet": {
"publishedAt": "2008-06-05T04:13:13.000Z",
"channelId": "UCtjLPHCyI5V-xuumAXzAizA",
"title": "UNUChannel",
"description": "Channel produced by the United Nations University (UNU). The overarching goal of the United Nations University is to contribute to global sustainable ...",
"thumbnails": {
"default": {
"url": "https://i.ytimg.com/i/tjLPHCyI5V-xuumAXzAizA/1.jpg"
},
"medium": {
"url": "https://i.ytimg.com/i/tjLPHCyI5V-xuumAXzAizA/mq1.jpg"
},
"high": {
"url": "https://i.ytimg.com/i/tjLPHCyI5V-xuumAXzAizA/hq1.jpg"
}
},
"channelTitle": "UNUChannel",
"liveBroadcastContent": "none"
}
},
{
"kind": "youtube#searchResult",
"etag": "\"iDqJ1j7zKs4x3o3ZsFlBOwgWAHU/44t2atyjsxpSOVj7OfeK9GTfy0M\"",
"id": {
"kind": "youtube#channel",
"channelId": "UCJ7-0_cR9HiA9iX8n3kugcg"
},
"snippet": {
"publishedAt": "2010-06-29T15:08:02.000Z",
"channelId": "UCJ7-0_cR9HiA9iX8n3kugcg",
"title": "Naturhistoriska riksmuseet",
"description": "Naturhistoriska riksmuseets och Cosmonovas YouTube-kanal.",
"thumbnails": {
"default": {
"url": "https://lh5.googleusercontent.com/-OItSjQXSj_c/AAAAAAAAAAI/AAAAAAAAAAA/ybdmiik-0eA/photo.jpg"
},
"medium": {
"url": "https://lh5.googleusercontent.com/-OItSjQXSj_c/AAAAAAAAAAI/AAAAAAAAAAA/ybdmiik-0eA/photo.jpg"
},
"high": {
"url": "https://lh5.googleusercontent.com/-OItSjQXSj_c/AAAAAAAAAAI/AAAAAAAAAAA/ybdmiik-0eA/photo.jpg"
}
},
"channelTitle": "SthlmNaturhistoriska",
"liveBroadcastContent": "none"
}
}
]
}
提前致谢。任何帮助将不胜感激。
regionCode - (string) The regionCode parameter instructs the API to return
search results for the specified country. The parameter value is an
ISO 3166-1 alpha-2 country code.
看起来指定区域代码 returns 搜索结果就像您 在那个国家 一样,而不是 videos/channels 与那个国家相关联。例如,如果您指定 CN(中国)作为区域代码,您将不会获得在中国被屏蔽的视频的结果。
似乎没有什么好的方法可以获取属于特定国家/地区的所有频道。您可以 做的是使用您指定的搜索条件执行search.list() 并设置type=Channel
。然后,根据响应,向 channels.list() 发出请求以获取国家并比较它是否来自该特定国家。这是非常低效的,当我尝试测试类似的方法时,我发现我可以在频道的 "About" 部分中设置我的国家/地区。但是,由于该字段是可选的,因此无法保证用户确实为其频道设置了此字段,因此最终您很难获得所需的信息。
我试图在 regionCode
的基础上获取不同的 YouTube 频道。
正在尝试获取印度 YouTube 频道:
https://www.googleapis.com/youtube/v3/search?part=snippet&type=channel®ionCode=IN&maxResults=5&key={API_KEY}
正在尝试获取马来西亚 YouTube 频道:
https://www.googleapis.com/youtube/v3/search?part=snippet&type=channel®ionCode=MY&maxResults=5&key={API_KEY}
这两个请求的结果相同。为什么会这样?
{
"kind": "youtube#searchListResponse",
"etag": "\"iDqJ1j7zKs4x3o3ZsFlBOwgWAHU/EiqwT6pG1EkwVEl17s1_qudvkmk\"",
"nextPageToken": "CAUQAA",
"pageInfo": {
"totalResults": 1000000,
"resultsPerPage": 5
},
"items": [
{
"kind": "youtube#searchResult",
"etag": "\"iDqJ1j7zKs4x3o3ZsFlBOwgWAHU/smpwgLdS9Og11NhpzRYcy37a9V8\"",
"id": {
"kind": "youtube#channel",
"channelId": "UCrFiA0hztL9e8zTi_qBuW4w"
},
"snippet": {
"publishedAt": "2013-03-19T20:35:41.000Z",
"channelId": "UCrFiA0hztL9e8zTi_qBuW4w",
"title": "EeOneGuy",
"description": "Просто делаю ролики =)",
"thumbnails": {
"default": {
"url": "https://lh6.googleusercontent.com/-ZPtgaY_lFDY/AAAAAAAAAAI/AAAAAAAAAAA/U_8gJcnIMiE/photo.jpg"
},
"medium": {
"url": "https://lh6.googleusercontent.com/-ZPtgaY_lFDY/AAAAAAAAAAI/AAAAAAAAAAA/U_8gJcnIMiE/photo.jpg"
},
"high": {
"url": "https://lh6.googleusercontent.com/-ZPtgaY_lFDY/AAAAAAAAAAI/AAAAAAAAAAA/U_8gJcnIMiE/photo.jpg"
}
},
"channelTitle": "EeOneGuy",
"liveBroadcastContent": "none"
}
},
{
"kind": "youtube#searchResult",
"etag": "\"iDqJ1j7zKs4x3o3ZsFlBOwgWAHU/g4m9Kno2zbU7BMIEUbffxDlyvZI\"",
"id": {
"kind": "youtube#channel",
"channelId": "UC7MO7ngSqsBcvQvxNf-kpWg"
},
"snippet": {
"publishedAt": "2013-06-04T17:39:49.000Z",
"channelId": "UC7MO7ngSqsBcvQvxNf-kpWg",
"title": "The Right to Research Coalition",
"description": "The Right to Research Coalition is a coalition of 80 undergraduate and graduate student organisations from across the world. Together we educate and ...",
"thumbnails": {
"default": {
"url": "https://lh5.googleusercontent.com/-p0RT2XiO3_0/AAAAAAAAAAI/AAAAAAAAAAA/tdAJTswPnB0/photo.jpg"
},
"medium": {
"url": "https://lh5.googleusercontent.com/-p0RT2XiO3_0/AAAAAAAAAAI/AAAAAAAAAAA/tdAJTswPnB0/photo.jpg"
},
"high": {
"url": "https://lh5.googleusercontent.com/-p0RT2XiO3_0/AAAAAAAAAAI/AAAAAAAAAAA/tdAJTswPnB0/photo.jpg"
}
},
"channelTitle": "R2RCvideo",
"liveBroadcastContent": "none"
}
},
{
"kind": "youtube#searchResult",
"etag": "\"iDqJ1j7zKs4x3o3ZsFlBOwgWAHU/nWC7qhbPZRH0qyEBOcWdFR8TI5k\"",
"id": {
"kind": "youtube#channel",
"channelId": "UCmSSq5573Ru9asXsXykgqTw"
},
"snippet": {
"publishedAt": "2014-10-12T02:26:56.000Z",
"channelId": "UCmSSq5573Ru9asXsXykgqTw",
"title": "Toys Games TV",
"description": "Welcome to Toys Games TV Channel! Looking for a safe channel for your kids? Look no further, on TGTV we review primarily Disney, PBS & Sprout character ...",
"thumbnails": {
"default": {
"url": "https://lh3.googleusercontent.com/-5qqjMUWhRow/AAAAAAAAAAI/AAAAAAAAAAA/2la9IA5DNhU/photo.jpg"
},
"medium": {
"url": "https://lh3.googleusercontent.com/-5qqjMUWhRow/AAAAAAAAAAI/AAAAAAAAAAA/2la9IA5DNhU/photo.jpg"
},
"high": {
"url": "https://lh3.googleusercontent.com/-5qqjMUWhRow/AAAAAAAAAAI/AAAAAAAAAAA/2la9IA5DNhU/photo.jpg"
}
},
"channelTitle": "ToysGamesTV",
"liveBroadcastContent": "upcoming"
}
},
{
"kind": "youtube#searchResult",
"etag": "\"iDqJ1j7zKs4x3o3ZsFlBOwgWAHU/enqEI6qDr8UfYcjixI9Cjpd6SU0\"",
"id": {
"kind": "youtube#channel",
"channelId": "UCtjLPHCyI5V-xuumAXzAizA"
},
"snippet": {
"publishedAt": "2008-06-05T04:13:13.000Z",
"channelId": "UCtjLPHCyI5V-xuumAXzAizA",
"title": "UNUChannel",
"description": "Channel produced by the United Nations University (UNU). The overarching goal of the United Nations University is to contribute to global sustainable ...",
"thumbnails": {
"default": {
"url": "https://i.ytimg.com/i/tjLPHCyI5V-xuumAXzAizA/1.jpg"
},
"medium": {
"url": "https://i.ytimg.com/i/tjLPHCyI5V-xuumAXzAizA/mq1.jpg"
},
"high": {
"url": "https://i.ytimg.com/i/tjLPHCyI5V-xuumAXzAizA/hq1.jpg"
}
},
"channelTitle": "UNUChannel",
"liveBroadcastContent": "none"
}
},
{
"kind": "youtube#searchResult",
"etag": "\"iDqJ1j7zKs4x3o3ZsFlBOwgWAHU/44t2atyjsxpSOVj7OfeK9GTfy0M\"",
"id": {
"kind": "youtube#channel",
"channelId": "UCJ7-0_cR9HiA9iX8n3kugcg"
},
"snippet": {
"publishedAt": "2010-06-29T15:08:02.000Z",
"channelId": "UCJ7-0_cR9HiA9iX8n3kugcg",
"title": "Naturhistoriska riksmuseet",
"description": "Naturhistoriska riksmuseets och Cosmonovas YouTube-kanal.",
"thumbnails": {
"default": {
"url": "https://lh5.googleusercontent.com/-OItSjQXSj_c/AAAAAAAAAAI/AAAAAAAAAAA/ybdmiik-0eA/photo.jpg"
},
"medium": {
"url": "https://lh5.googleusercontent.com/-OItSjQXSj_c/AAAAAAAAAAI/AAAAAAAAAAA/ybdmiik-0eA/photo.jpg"
},
"high": {
"url": "https://lh5.googleusercontent.com/-OItSjQXSj_c/AAAAAAAAAAI/AAAAAAAAAAA/ybdmiik-0eA/photo.jpg"
}
},
"channelTitle": "SthlmNaturhistoriska",
"liveBroadcastContent": "none"
}
}
]
}
提前致谢。任何帮助将不胜感激。
regionCode - (string) The regionCode parameter instructs the API to return search results for the specified country. The parameter value is an ISO 3166-1 alpha-2 country code.
看起来指定区域代码 returns 搜索结果就像您 在那个国家 一样,而不是 videos/channels 与那个国家相关联。例如,如果您指定 CN(中国)作为区域代码,您将不会获得在中国被屏蔽的视频的结果。
似乎没有什么好的方法可以获取属于特定国家/地区的所有频道。您可以 做的是使用您指定的搜索条件执行search.list() 并设置type=Channel
。然后,根据响应,向 channels.list() 发出请求以获取国家并比较它是否来自该特定国家。这是非常低效的,当我尝试测试类似的方法时,我发现我可以在频道的 "About" 部分中设置我的国家/地区。但是,由于该字段是可选的,因此无法保证用户确实为其频道设置了此字段,因此最终您很难获得所需的信息。