使用 alt=json-in-script&callback 检索 info V3 youtube API
Posted
技术标签:
【中文标题】使用 alt=json-in-script&callback 检索 info V3 youtube API【英文标题】:Retrieve info V3 youtube API with alt=json-in-script&callback 【发布时间】:2015-06-17 00:18:19 【问题描述】:有谁知道如何使用 V3 API 做到这一点?
本例使用 V2
http://gdata.youtube.com/feeds/api/videos/gzDS-Kfd5XQ?v=2&alt=json-in-script&callback=whatever
而且callcack是
<script type="text/javascript">function youtube' . $random . '(data)document.getElementById(\'title' . $code . '\').title = data.entry[ \'title\' ].$t.substr(0,100);</script>
【问题讨论】:
我认为,由于 v3 是原生 JSON 并且完全符合 CORS,您只需进行常规 ajax 调用,当数据返回时,使用它触发回调 ...换句话说,in 旨在消除对 JSONP 的需求。 你是怎么做到的?刚刚注意到我获取标题/描述等的方式现在只返回HTTPS://YOUTUBE.COM/DEVICESUPPORT
。您是否必须获取 v3 的 API 密钥,或者是否还有像 gdata 这样的 URL 来获取视频数据?
【参考方案1】:
Vadim 解决方案不起作用(至少对我而言)。答案在这里https://developers.google.com/youtube/v3/sample_requests
例子:
https://www.googleapis.com/youtube/v3/videos?id=qzaBVoti3U0&key=[YOURAPIKEY]&part=snippet,contentDetails,statistics,status
将返回如下数据:
"kind": "youtube#videoListResponse",
"etag": "\"dhbhlDw5j8dK10GxeV_UG6RSReM/kvqkY8X2aXhk-O8BnczihZb8PG8\"",
"pageInfo":
"totalResults": 1,
"resultsPerPage": 1
,
"items": [
"kind": "youtube#video",
"etag": "\"dhbhlDw5j8dK10GxeV_UG6RSReM/ZCKauTkB1Y03qtXLwyD0nf4m7gY\"",
"id": "qzaBVoti3U0",
"snippet":
"publishedAt": "2015-03-17T01:44:05.000Z",
"channelId": "UC4yfiEBmRDMyk4LuJH7Ckzg",
"title": "Road Rash 3DO - Level 1 Completo",
"description": "►REVIEW no Memória BIT http://wp.me/p4n6ZH-2eu ◄\n\nRoad Rash era show de diversão no Mega Drive e a versão 3DO não mudou isto em nada. Confira o gameplay completo do Level 1, incluindo intro e algumas cenas intermediárias. \nControle: Daniel Lemes\n*****\nRoad Rash was pure fun on Sega Genesis, so as the 3DO version. Check out this gameplay including full Level 1, intro and some cutscenes. \nControls: Daniel Lemes.\n\n\n© 1994 Electronic Arts - ALL RIGHTS RESERVED\n© 1991-1994 A&M Records - ALL RIGHTS RESERVED",
"thumbnails":
"default":
"url": "https://i.ytimg.com/vi/qzaBVoti3U0/default.jpg",
"width": 120,
"height": 90
,
"medium":
"url": "https://i.ytimg.com/vi/qzaBVoti3U0/mqdefault.jpg",
"width": 320,
"height": 180
,
"high":
"url": "https://i.ytimg.com/vi/qzaBVoti3U0/hqdefault.jpg",
"width": 480,
"height": 360
,
"standard":
"url": "https://i.ytimg.com/vi/qzaBVoti3U0/sddefault.jpg",
"width": 640,
"height": 480
,
"maxres":
"url": "https://i.ytimg.com/vi/qzaBVoti3U0/maxresdefault.jpg",
"width": 1280,
"height": 720
,
"channelTitle": "Memória BIT",
"categoryId": "20",
"liveBroadcastContent": "none",
"localized":
"title": "Road Rash 3DO - Level 1 Completo",
"description": "►REVIEW no Memória BIT http://wp.me/p4n6ZH-2eu ◄\n\nRoad Rash era show de diversão no Mega Drive e a versão 3DO não mudou isto em nada. Confira o gameplay completo do Level 1, incluindo intro e algumas cenas intermediárias. \nControle: Daniel Lemes\n*****\nRoad Rash was pure fun on Sega Genesis, so as the 3DO version. Check out this gameplay including full Level 1, intro and some cutscenes. \nControls: Daniel Lemes.\n\n\n© 1994 Electronic Arts - ALL RIGHTS RESERVED\n© 1991-1994 A&M Records - ALL RIGHTS RESERVED"
,
"contentDetails":
"duration": "PT24M47S",
"dimension": "2d",
"definition": "hd",
"caption": "false",
"licensedContent": false,
"regionRestriction":
"blocked": [
"DE"
]
,
"status":
"uploadStatus": "processed",
"privacyStatus": "public",
"license": "youtube",
"embeddable": true,
"publicStatsViewable": true
,
"statistics":
"viewCount": "48",
"likeCount": "1",
"dislikeCount": "0",
"favoriteCount": "0",
"commentCount": "2"
]
【讨论】:
以上是关于使用 alt=json-in-script&callback 检索 info V3 youtube API的主要内容,如果未能解决你的问题,请参考以下文章