Youtube 视频标题 API v3 没有 API 键?
Youtube Video title with API v3 without API key?
是否可以使用带有 API v3 的视频 ID 而无需 API 密钥来获取视频标题?我在 API 文档中找不到任何信息或获取标题的示例。
要获取视频标题,您将需要一个API密钥,并且您需要向以下地址发出请求:
https://www.googleapis.com/youtube/v3/videos?part=snippet&id={COMMA_DELIMITED_LIST_OF_IDS}&key={YOUR_API_KEY}
在返回的数据包中,标题将位于 items.snippet.title
如果没有 API 键,您将无法检索 任何 API 数据;所有 API 请求都在配额系统上,密钥用于确定向您的应用程序的每日限额收取多少费用。但是,像上面这样的调用非常便宜;总共有 3 个单元(2 个用于代码片段,1 个用于请求本身)。由于您每天获得 50,000,000 个单位,并且可以为同样的 3 个单位检索最多 50 个片段,因此使用 API 键并不是什么负担。
不需要API键
要获取视频标题,您 不需要 需要一个 API 密钥,并且您需要向以下地址发出请求:
https://noembed.com/embed?url=https://www.youtube.com/watch?v=dQw4w9WgXcQ
为您需要的视频更改 YouTube URL。
它也适用于 Vimeo 和许多其他 supported sites 以及 URL,例如:
https://noembed.com/embed?url=https://vimeo.com/45196609
详情
如果您直接使用 API,则在没有 API 密钥的情况下,无法使用带有 API v3 的视频 ID 获取视频标题。 YouTube 数据 API v2 已弃用(参见:YouTube Data API v2 Deprecation: Frequently Asked Questions) and currently the YouTube API doesn't support oEmbed with JSONP as it should (see Issue 4329: oEmbed callback for JSONP)。
但幸运的是,有 Noembed 服务可以让您使用 JSONP 而无需 API 密钥获取 YouTube 视频的标题(和其他数据)。
演示
这是一个简单的演示,可以使用 jQuery 获得标题:
var id = 'dQw4w9WgXcQ';
var url = 'https://www.youtube.com/watch?v=' + id;
$.getJSON('https://noembed.com/embed',
{format: 'json', url: url}, function (data) {
alert(data.title);
});
参见 JS Bin 上的 DEMO。
另请参阅这些问题:
这正是oEmbed协议的意思。
oEmbed is a format for allowing an embedded representation of a URL on
third party sites. The simple API allows a website to display embedded
content (such as photos or videos) when a user posts a link to that
resource, without having to parse the resource directly.
This document is stored on GitHub.
有关格式的更多信息:https://oembed.com
https://www.youtube.com/oembed?url=http%3A//youtube.com/watch%3Fv%3DM3r2XDceM6A&format=json
示例输出:
{
"version": "1.0",
"type": "video",
"provider_name": "YouTube",
"provider_url": "http://youtube.com/",
"width": 425,
"height": 344,
"title": "Amazing Nintendo Facts",
"author_name": "ZackScott",
"author_url": "http://www.youtube.com/user/ZackScott",
"html":
"<object width=\"425\" height=\"344\">
<param name=\"movie\" value=\"http://www.youtube.com/v/M3r2XDceM6A&fs=1\"></param>
<param name=\"allowFullScreen\" value=\"true\"></param>
<param name=\"allowscriptaccess\" value=\"always\"></param>
<embed src=\"http://www.youtube.com/v/M3r2XDceM6A&fs=1\"
type=\"application/x-shockwave-flash\" width=\"425\" height=\"344\"
allowscriptaccess=\"always\" allowfullscreen=\"true\"></embed>
</object>",
}
以下是声明遵守格式的内容提供商列表:
"provider_name": "23HQ",
"provider_name": "Adways",
"provider_name": "Alpha App Net",
"provider_name": "amCharts Live Editor",
"provider_name": "Animatron",
"provider_name": "Animoto",
"provider_name": "Audiomack",
"provider_name": "AudioSnaps",
"provider_name": "Blackfire.io",
"provider_name": "Box Office Buz",
"provider_name": "Buttondown",
"provider_name": "Cacoo",
"provider_name": "Carbon Health",
"provider_name": "CatBoat",
"provider_name": "ChartBlocks",
"provider_name": "chirbit.com",
"provider_name": "CircuitLab",
"provider_name": "Clipland",
"provider_name": "Clyp",
"provider_name": "Codepen",
"provider_name": "Codepoints",
"provider_name": "CodeSandbox",
"provider_name": "CollegeHumor",
"provider_name": "Commaful",
"provider_name": "Coub",
"provider_name": "Crowd Ranking",
"provider_name": "Cyrano Systems",
"provider_name": "Daily Mile",
"provider_name": "Dailymotion",
"provider_name": "Deviantart.com",
"provider_name": "Didacte",
"provider_name": "Dipity",
"provider_name": "DocDroid",
"provider_name": "Docs",
"provider_name": "Dotsub",
"provider_name": "edocr",
"provider_name": "eduMedia",
"provider_name": "EgliseInfo",
"provider_name": "Embed Articles",
"provider_name": "Embedly",
"provider_name": "Ethfiddle",
"provider_name": "Eyrie",
"provider_name": "Facebook (Video)",
"provider_name": "Flat",
"provider_name": "Flickr",
"provider_name": "FOX SPORTS Australia",
"provider_name": "FrameBuzz",
"provider_name": "FunnyOrDie",
"provider_name": "Geograph Britain and Ireland",
"provider_name": "Geograph Channel Islands",
"provider_name": "Geograph Germany",
"provider_name": "Getty Images",
"provider_name": "Gfycat",
"provider_name": "GIPHY",
"provider_name": "Gyazo",
"provider_name": "HuffDuffer",
"provider_name": "Hulu",
"provider_name": "iFixit",
"provider_name": "IFTTT",
"provider_name": "Indaco",
"provider_name": "Infogram",
"provider_name": "Inoreader",
"provider_name": "inphood",
"provider_name": "Instagram",
"provider_name": "iSnare Articles",
"provider_name": "ivlismusic",
"provider_name": "Kickstarter",
"provider_name": "Kidoju",
"provider_name": "Kit",
"provider_name": "Kitchenbowl",
"provider_name": "Knacki",
"provider_name": "LearningApps.org",
"provider_name": "Ludus",
"provider_name": "MathEmbed",
"provider_name": "me.me",
"provider_name": "Meetup",
"provider_name": "MixCloud",
"provider_name": "Moby Picture",
"provider_name": "Modelo",
"provider_name": "myBeweeg",
"provider_name": "nanoo.tv",
"provider_name": "nfb.ca",
"provider_name": "Odds.com.au",
"provider_name": "Office Mix",
"provider_name": "Official FM",
"provider_name": "On Aol",
"provider_name": "Ora TV",
"provider_name": "Orbitvu",
"provider_name": "Oumy",
"provider_name": "Pastery",
"provider_name": "Pixdor",
"provider_name": "Poll Daddy",
"provider_name": "Port",
"provider_name": "Portfolium",
"provider_name": "Punters",
"provider_name": "Quiz.biz",
"provider_name": "Quizz.biz",
"provider_name": "RapidEngage",
"provider_name": "Reddit",
"provider_name": "ReleaseWire",
"provider_name": "RepubHub",
"provider_name": "ReverbNation",
"provider_name": "Roomshare",
"provider_name": "Rumble",
"provider_name": "Sapo Videos",
"provider_name": "Screen9",
"provider_name": "Screencast.com",
"provider_name": "Screenr",
"provider_name": "ScribbleMaps",
"provider_name": "Scribd",
"provider_name": "ShortNote",
"provider_name": "Shoudio",
"provider_name": "Show the Way, actionable location info",
"provider_name": "Silk",
"provider_name": "Simplecast",
"provider_name": "Sizzle",
"provider_name": "Sketchfab",
"provider_name": "SlideShare",
"provider_name": "SmugMug",
"provider_name": "SocialExplorer",
"provider_name": "Songlink",
"provider_name": "SoundCloud",
"provider_name": "Soundsgood",
"provider_name": "SpeakerDeck",
"provider_name": "Spotful",
"provider_name": "Spreaker",
"provider_name": "Streamable",
"provider_name": "StreamOneCloud",
"provider_name": "Sutori",
"provider_name": "Sway",
"provider_name": "Ted",
"provider_name": "The New York Times",
"provider_name": "They Said So",
"provider_name": "TickCounter",
"provider_name": "Toornament",
"provider_name": "Topy",
"provider_name": "Twitch",
"provider_name": "Twitter",
"provider_name": "Ubideo",
"provider_name": "UOL",
"provider_name": "Ustream",
"provider_name": "Utposts",
"provider_name": "Uttles",
"provider_name": "VeeR VR",
"provider_name": "Verse",
"provider_name": "VEVO",
"provider_name": "VideoJug",
"provider_name": "Vidlit",
"provider_name": "Vimeo",
"provider_name": "Vlipsy",
"provider_name": "wecandeo",
"provider_name": "Wiredrive",
"provider_name": "wizer.me",
"provider_name": "Wootled",
"provider_name": "WordPress.com",
"provider_name": "Yes, I Know IT!",
"provider_name": "YFrog",
"provider_name": "YouTube",
"provider_name": "ZProvider",
请注意,这并不意味着 CORS 已在此网站上启用。
此数据主要用于服务器端解析。
大部分信息也可以通过解析给定页面的 <meta og>
open graph html 属性获得。
有关开放图的信息,请参阅 http://ogp.me/。
是的,你可以没有任何API只是请求和re模块
Python中的代码:
import requests,re
video_url = "https://www.youtube.com/watch?v=2i2khp_npdE"
response = requests.get(video_url).text
title = re.findall(r'"title":"[^>]*",',response)[0].split(',')[0][9:-1]
print("\n[+] Video Title: {}".format(title))
输出:
[+] 视频标题:Alan Walker - 唱歌让我入睡
是的,有可能。
我对 excellent Porto's answer here 做了一些修改,并在 Python 上写了这个片段:
import urllib, urllib.request, json
input = "C:\urls.txt"
output = "C:\tracks.csv"
urls=[line.strip() for line in open(input)]
for url in urls:
ID = url.split('=')
VideoID = ID[1]
params = {"format": "json", "url": "https://www.youtube.com/watch?v=%s" % VideoID}
url = "https://www.youtube.com/oembed"
query_string = urllib.parse.urlencode(params)
url = url + "?" + query_string
with urllib.request.urlopen(url) as response:
response_text = response.read()
try:
data = json.loads(response_text.decode())
except ValueError as e:
continue # skip faulty url
if data is not None:
author = data['author_name'].split(' - ')
author = author[0].rstrip()
f = open(output, "a", encoding='utf-8')
print(author, ',', data['title'], sep="", file=f)
它选择一个包含 Youtube URL 列表的文本文件:
https://www.youtube.com/watch?v=F_Vfgdfgg
https://www.youtube.com/watch?v=RndfgdfN8
...
和 returns 具有 Artist-Title 对的 CSV 文件:
Beyonce,Pretty hurts
Justin Timberlake,Cry me a river
P.S。片段中的文件路径格式适用于 Windows,对于 Linux 只需使用 ~/tracks.csv
是否可以使用带有 API v3 的视频 ID 而无需 API 密钥来获取视频标题?我在 API 文档中找不到任何信息或获取标题的示例。
要获取视频标题,您将需要一个API密钥,并且您需要向以下地址发出请求:
https://www.googleapis.com/youtube/v3/videos?part=snippet&id={COMMA_DELIMITED_LIST_OF_IDS}&key={YOUR_API_KEY}
在返回的数据包中,标题将位于 items.snippet.title
如果没有 API 键,您将无法检索 任何 API 数据;所有 API 请求都在配额系统上,密钥用于确定向您的应用程序的每日限额收取多少费用。但是,像上面这样的调用非常便宜;总共有 3 个单元(2 个用于代码片段,1 个用于请求本身)。由于您每天获得 50,000,000 个单位,并且可以为同样的 3 个单位检索最多 50 个片段,因此使用 API 键并不是什么负担。
不需要API键
要获取视频标题,您 不需要 需要一个 API 密钥,并且您需要向以下地址发出请求:
https://noembed.com/embed?url=https://www.youtube.com/watch?v=dQw4w9WgXcQ
为您需要的视频更改 YouTube URL。
它也适用于 Vimeo 和许多其他 supported sites 以及 URL,例如:
https://noembed.com/embed?url=https://vimeo.com/45196609
详情
如果您直接使用 API,则在没有 API 密钥的情况下,无法使用带有 API v3 的视频 ID 获取视频标题。 YouTube 数据 API v2 已弃用(参见:YouTube Data API v2 Deprecation: Frequently Asked Questions) and currently the YouTube API doesn't support oEmbed with JSONP as it should (see Issue 4329: oEmbed callback for JSONP)。
但幸运的是,有 Noembed 服务可以让您使用 JSONP 而无需 API 密钥获取 YouTube 视频的标题(和其他数据)。
演示
这是一个简单的演示,可以使用 jQuery 获得标题:
var id = 'dQw4w9WgXcQ';
var url = 'https://www.youtube.com/watch?v=' + id;
$.getJSON('https://noembed.com/embed',
{format: 'json', url: url}, function (data) {
alert(data.title);
});
参见 JS Bin 上的 DEMO。
另请参阅这些问题:
这正是oEmbed协议的意思。
oEmbed is a format for allowing an embedded representation of a URL on third party sites. The simple API allows a website to display embedded content (such as photos or videos) when a user posts a link to that resource, without having to parse the resource directly.
This document is stored on GitHub.
有关格式的更多信息:https://oembed.com
https://www.youtube.com/oembed?url=http%3A//youtube.com/watch%3Fv%3DM3r2XDceM6A&format=json
示例输出:
{
"version": "1.0",
"type": "video",
"provider_name": "YouTube",
"provider_url": "http://youtube.com/",
"width": 425,
"height": 344,
"title": "Amazing Nintendo Facts",
"author_name": "ZackScott",
"author_url": "http://www.youtube.com/user/ZackScott",
"html":
"<object width=\"425\" height=\"344\">
<param name=\"movie\" value=\"http://www.youtube.com/v/M3r2XDceM6A&fs=1\"></param>
<param name=\"allowFullScreen\" value=\"true\"></param>
<param name=\"allowscriptaccess\" value=\"always\"></param>
<embed src=\"http://www.youtube.com/v/M3r2XDceM6A&fs=1\"
type=\"application/x-shockwave-flash\" width=\"425\" height=\"344\"
allowscriptaccess=\"always\" allowfullscreen=\"true\"></embed>
</object>",
}
以下是声明遵守格式的内容提供商列表:
"provider_name": "23HQ",
"provider_name": "Adways",
"provider_name": "Alpha App Net",
"provider_name": "amCharts Live Editor",
"provider_name": "Animatron",
"provider_name": "Animoto",
"provider_name": "Audiomack",
"provider_name": "AudioSnaps",
"provider_name": "Blackfire.io",
"provider_name": "Box Office Buz",
"provider_name": "Buttondown",
"provider_name": "Cacoo",
"provider_name": "Carbon Health",
"provider_name": "CatBoat",
"provider_name": "ChartBlocks",
"provider_name": "chirbit.com",
"provider_name": "CircuitLab",
"provider_name": "Clipland",
"provider_name": "Clyp",
"provider_name": "Codepen",
"provider_name": "Codepoints",
"provider_name": "CodeSandbox",
"provider_name": "CollegeHumor",
"provider_name": "Commaful",
"provider_name": "Coub",
"provider_name": "Crowd Ranking",
"provider_name": "Cyrano Systems",
"provider_name": "Daily Mile",
"provider_name": "Dailymotion",
"provider_name": "Deviantart.com",
"provider_name": "Didacte",
"provider_name": "Dipity",
"provider_name": "DocDroid",
"provider_name": "Docs",
"provider_name": "Dotsub",
"provider_name": "edocr",
"provider_name": "eduMedia",
"provider_name": "EgliseInfo",
"provider_name": "Embed Articles",
"provider_name": "Embedly",
"provider_name": "Ethfiddle",
"provider_name": "Eyrie",
"provider_name": "Facebook (Video)",
"provider_name": "Flat",
"provider_name": "Flickr",
"provider_name": "FOX SPORTS Australia",
"provider_name": "FrameBuzz",
"provider_name": "FunnyOrDie",
"provider_name": "Geograph Britain and Ireland",
"provider_name": "Geograph Channel Islands",
"provider_name": "Geograph Germany",
"provider_name": "Getty Images",
"provider_name": "Gfycat",
"provider_name": "GIPHY",
"provider_name": "Gyazo",
"provider_name": "HuffDuffer",
"provider_name": "Hulu",
"provider_name": "iFixit",
"provider_name": "IFTTT",
"provider_name": "Indaco",
"provider_name": "Infogram",
"provider_name": "Inoreader",
"provider_name": "inphood",
"provider_name": "Instagram",
"provider_name": "iSnare Articles",
"provider_name": "ivlismusic",
"provider_name": "Kickstarter",
"provider_name": "Kidoju",
"provider_name": "Kit",
"provider_name": "Kitchenbowl",
"provider_name": "Knacki",
"provider_name": "LearningApps.org",
"provider_name": "Ludus",
"provider_name": "MathEmbed",
"provider_name": "me.me",
"provider_name": "Meetup",
"provider_name": "MixCloud",
"provider_name": "Moby Picture",
"provider_name": "Modelo",
"provider_name": "myBeweeg",
"provider_name": "nanoo.tv",
"provider_name": "nfb.ca",
"provider_name": "Odds.com.au",
"provider_name": "Office Mix",
"provider_name": "Official FM",
"provider_name": "On Aol",
"provider_name": "Ora TV",
"provider_name": "Orbitvu",
"provider_name": "Oumy",
"provider_name": "Pastery",
"provider_name": "Pixdor",
"provider_name": "Poll Daddy",
"provider_name": "Port",
"provider_name": "Portfolium",
"provider_name": "Punters",
"provider_name": "Quiz.biz",
"provider_name": "Quizz.biz",
"provider_name": "RapidEngage",
"provider_name": "Reddit",
"provider_name": "ReleaseWire",
"provider_name": "RepubHub",
"provider_name": "ReverbNation",
"provider_name": "Roomshare",
"provider_name": "Rumble",
"provider_name": "Sapo Videos",
"provider_name": "Screen9",
"provider_name": "Screencast.com",
"provider_name": "Screenr",
"provider_name": "ScribbleMaps",
"provider_name": "Scribd",
"provider_name": "ShortNote",
"provider_name": "Shoudio",
"provider_name": "Show the Way, actionable location info",
"provider_name": "Silk",
"provider_name": "Simplecast",
"provider_name": "Sizzle",
"provider_name": "Sketchfab",
"provider_name": "SlideShare",
"provider_name": "SmugMug",
"provider_name": "SocialExplorer",
"provider_name": "Songlink",
"provider_name": "SoundCloud",
"provider_name": "Soundsgood",
"provider_name": "SpeakerDeck",
"provider_name": "Spotful",
"provider_name": "Spreaker",
"provider_name": "Streamable",
"provider_name": "StreamOneCloud",
"provider_name": "Sutori",
"provider_name": "Sway",
"provider_name": "Ted",
"provider_name": "The New York Times",
"provider_name": "They Said So",
"provider_name": "TickCounter",
"provider_name": "Toornament",
"provider_name": "Topy",
"provider_name": "Twitch",
"provider_name": "Twitter",
"provider_name": "Ubideo",
"provider_name": "UOL",
"provider_name": "Ustream",
"provider_name": "Utposts",
"provider_name": "Uttles",
"provider_name": "VeeR VR",
"provider_name": "Verse",
"provider_name": "VEVO",
"provider_name": "VideoJug",
"provider_name": "Vidlit",
"provider_name": "Vimeo",
"provider_name": "Vlipsy",
"provider_name": "wecandeo",
"provider_name": "Wiredrive",
"provider_name": "wizer.me",
"provider_name": "Wootled",
"provider_name": "WordPress.com",
"provider_name": "Yes, I Know IT!",
"provider_name": "YFrog",
"provider_name": "YouTube",
"provider_name": "ZProvider",
请注意,这并不意味着 CORS 已在此网站上启用。
此数据主要用于服务器端解析。
大部分信息也可以通过解析给定页面的 <meta og>
open graph html 属性获得。
有关开放图的信息,请参阅 http://ogp.me/。
是的,你可以没有任何API只是请求和re模块
Python中的代码:
import requests,re
video_url = "https://www.youtube.com/watch?v=2i2khp_npdE"
response = requests.get(video_url).text
title = re.findall(r'"title":"[^>]*",',response)[0].split(',')[0][9:-1]
print("\n[+] Video Title: {}".format(title))
输出:
[+] 视频标题:Alan Walker - 唱歌让我入睡
是的,有可能。
我对 excellent Porto's answer here 做了一些修改,并在 Python 上写了这个片段:
import urllib, urllib.request, json
input = "C:\urls.txt"
output = "C:\tracks.csv"
urls=[line.strip() for line in open(input)]
for url in urls:
ID = url.split('=')
VideoID = ID[1]
params = {"format": "json", "url": "https://www.youtube.com/watch?v=%s" % VideoID}
url = "https://www.youtube.com/oembed"
query_string = urllib.parse.urlencode(params)
url = url + "?" + query_string
with urllib.request.urlopen(url) as response:
response_text = response.read()
try:
data = json.loads(response_text.decode())
except ValueError as e:
continue # skip faulty url
if data is not None:
author = data['author_name'].split(' - ')
author = author[0].rstrip()
f = open(output, "a", encoding='utf-8')
print(author, ',', data['title'], sep="", file=f)
它选择一个包含 Youtube URL 列表的文本文件:
https://www.youtube.com/watch?v=F_Vfgdfgg
https://www.youtube.com/watch?v=RndfgdfN8
...
和 returns 具有 Artist-Title 对的 CSV 文件:
Beyonce,Pretty hurts
Justin Timberlake,Cry me a river
P.S。片段中的文件路径格式适用于 Windows,对于 Linux 只需使用 ~/tracks.csv