Youtube API v3 data.search 返回相同的值
Posted
技术标签:
【中文标题】Youtube API v3 data.search 返回相同的值【英文标题】:Youtube API v3 data.search returning same value 【发布时间】:2015-10-17 01:04:21 【问题描述】:我试图根据 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"
]
提前致谢。任何帮助将不胜感激。
【问题讨论】:
【参考方案1】:来自documentation:
regionCode - (string) regionCode参数指示API返回 指定国家的搜索结果。参数值为 ISO 3166-1 alpha-2 国家代码。
看起来指定 regionCode 会返回搜索结果,就像您在 那个国家一样,而不是与该国家相关联的视频/频道。例如,如果您指定 CN(中国)作为区域代码,您将无法获得在中国被屏蔽的视频的结果。
似乎没有什么好方法可以获取属于特定国家/地区的所有频道。您可以做的是使用您指定的搜索条件执行 search.list() 并设置type=Channel
。然后,根据响应,向 channels.list() 发出请求以获取国家/地区并进行比较以查看它是否来自该特定国家/地区。这非常低效,当我尝试测试类似的方法时,我发现我可以在频道的“关于”部分设置我的国家。但是,由于该字段是可选的,因此无法保证用户实际上是为其频道设置的,因此最终您很难获得所需的信息。
【讨论】:
以上是关于Youtube API v3 data.search 返回相同的值的主要内容,如果未能解决你的问题,请参考以下文章
Youtube /v3/search API 不再返回直播视频