@activelylearn/oembed 中文文档教程
node-oembed
来自 oEmbed.com:
oEmbed 是一种允许嵌入 URL 表示的格式 在第三方网站上。 简单的 API 允许网站显示 用户发布链接时嵌入的内容(例如照片或视频) 到该资源,而不必直接解析资源。
该库允许您发现和检索 oEmbed JSON 这些帖子的描述符。 它会自动转换额外的 为方便起见,将 XML 格式转换为 JavaScript 对象。 这个包 附带多种工具,可让您使用 oEmbed 信息。
Installation
npm i oembed
不要忘记稍后将其放入 package.json
的 dependencies
如果您在节点应用程序中使用它。
Features
支持
application/json+oembed
text/xml+oembed
当提供 API 密钥时自动 Embed.ly 回退
使用 htmlparser 用于 HTML 和 XML 解析
Tools (bin/)
oembed_get <URL>
检索和显示自定义 URL 的嵌入信息。
oembed_httpd <bind-port> [bind-host]
在简单的 Web 服务器中复制 embed.ly API。
oembeddiffjson_xml <URL>
比较 URL 的 JSON 和 XML 描述符。
API (require('oembed'))
在真实世界的应用程序中,您所需要的只是 fetch 函数来获取 o嵌入信息。 我们总是使用 函数回调(错误, 结果)
约定。
oembed.fetch(url, { maxwidth: 1920 }, function(error, result) {
if (error)
console.error(error);
else
console.log("oEmbed result", result);
});
当您需要更多时,可以单独执行这两个步骤 控制:
oembed.discover(url, callback)
finds all<link rel="alternate">
in a document- Get and parse descriptors immediately with
oembed.fetchJSON(url, callback)
andoembed.fetchXML(url, callback)
if you have discovery information already
Embed.ly fallback
Embed.ly 服务甚至可以为资源提供 oEmbed 信息 不提供 oEmbed 链接。 去 注册并配置 你的 API 密钥如:
oembed.EMBEDLY_KEY = "...";
TODO
- Document size limits?
- bin/oembed_httpd: Multiple URLs like embed.ly
- bin/oembed_httpd: Pass through for ETags and Last-Modified
node-oembed
From oEmbed.com:
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 library allows you to discover and retrieve the oEmbed JSON descriptors for these posts. It automatically converts the additional XML format to JavaScript objects for your convenience. This package comes with multiple tools that allow you to consume oEmbed information.
Installation
npm i oembed
Don't forget to put it in dependencies
of your package.json
later if you use this in a node app.
Features
Supports both
application/json+oembed
text/xml+oembed
Automatic Embed.ly fallback when an API key is provided
Uses htmlparser for HTML and XML parsing
Tools (bin/)
oembed_get <URL>
Retrieve and display oEmbed information for a custom URL.
oembed_httpd <bind-port> [bind-host]
Replicates the embed.ly API in a simple Web server.
oembeddiffjson_xml <URL>
Compare JSON and XML descriptors for a URL.
API (require('oembed'))
In a real-world app all you should need is the fetch function to get oEmbed information. We always use the function callback(error, result)
convention.
oembed.fetch(url, { maxwidth: 1920 }, function(error, result) {
if (error)
console.error(error);
else
console.log("oEmbed result", result);
});
The two steps can be executed separately whenever you need more control:
oembed.discover(url, callback)
finds all<link rel="alternate">
in a document- Get and parse descriptors immediately with
oembed.fetchJSON(url, callback)
andoembed.fetchXML(url, callback)
if you have discovery information already
Embed.ly fallback
The Embed.ly service can deliver oEmbed information even for resources that don't provide oEmbed links. Go sign up with them and configure your API key like:
oembed.EMBEDLY_KEY = "...";
TODO
- Document size limits?
- bin/oembed_httpd: Multiple URLs like embed.ly
- bin/oembed_httpd: Pass through for ETags and Last-Modified