# Instagram TV 一键内嵌

**URL:** https://meta.discourse.org/t/instagram-tv-oneboxing/172784
**Category:** Feature
**Created:** [2020年十二月9日 17:34 UTC](https://meta.discourse.org/t/instagram-tv-oneboxing/172784 "2020-12-09T17:34:36Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![renato](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/renato/32/383632_2.png) [@renato](https://meta.discourse.org/u/renato)
#### Post date: [2020年十二月9日 17:34 UTC](https://meta.discourse.org/t/instagram-tv-oneboxing/172784/1 "2020-12-09T17:34:36Z")

</div>

抱歉，如果这个问题之前已经讨论过，请问支持 IGTV 链接的“一键预览”（oneboxing）功能是否在开发计划中？

当我尝试使用 IGTV 链接（例如 `https://www.instagram.com/tv/ID/`）时，返回的结果与 [这个话题](https://meta.discourse.org/t/why-instagram-link-onebox-like-this/138047) 中描述的情况类似：

[https://www.instagram.com/tv/CIlKL1OBwE0/?hl=pt-br](https://www.instagram.com/tv/CIlKL1OBwE0/?hl=pt-br)

通过 cURL 访问该链接，可以看到存在 `og:image`、`og:description`、`og:video` 等元数据。

简单查看后发现，该 URL 尚未被 Instagram 的一键预览引擎支持：

> <https://github.com/discourse/onebox/blob/main/lib/onebox/engine/instagram_onebox.rb#L10-L15>

谢谢。

---

<div class="post-metadata">

### Author: ![codinghorror](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/codinghorror/32/110067_2.png) [@codinghorror](https://meta.discourse.org/u/codinghorror)
#### Post date: [2020年十二月9日 17:35 UTC](https://meta.discourse.org/t/instagram-tv-oneboxing/172784/2 "2020-12-09T17:35:54Z")

</div>

@jamie.wilson，这样应该可以吧？

---

<div class="post-metadata">

### Author: ![jamie.wilson](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/jamie.wilson/32/185466_2.png) [@jamie.wilson](https://meta.discourse.org/u/jamie.wilson)
#### Post date: [2020年十二月9日 22:07 UTC](https://meta.discourse.org/t/instagram-tv-oneboxing/172784/4 "2020-12-09T22:07:33Z")

</div>

目前，IGTV 链接将通过通用 oneboxer 进行路由，这（可能）对来自任何特定站点的前几次请求有效。但在少量请求之后，Instagram（可能）会将这些请求重定向到登录页面，这正是 @renato 遇到的情况。

正如 @renato 指出的那样，Instagram 的 onebox 引擎尚未配置为处理 IGTV 风格的链接。我刚刚创建了一个 PR 来实现这一功能：

> <https://github.com/discourse/onebox/pull/446>
>
> Instagram TV (or ‘IGTV’) links should be processed by the Instagram Onebox Engin…e. This means the data will be fetched via Instagram’s official oEmbed endpoint and, if an access token is configured, will not be subject to login redirects, etc.

这意味着 Instagram 的 onebox 引擎将通过官方 Instagram oEmbed 端点获取 IGTV URL。假设您已经[配置了访问令牌](https://meta.discourse.org/t/instagram-and-facebook-oembed-api-to-stop-working-what-about-onebox/164242/9)，onebox URL 请求将不会被重定向到登录页面。

（该 onebox PR 需要升级 onebox 版本，然后更新 Discourse 核心中的 Gemfile。）

---

<div class="post-metadata">

### Author: ![renato](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/renato/32/383632_2.png) [@renato](https://meta.discourse.org/u/renato)
#### Post date: [2020年十二月9日 23:28 UTC](https://meta.discourse.org/t/instagram-tv-oneboxing/172784/5 "2020-12-09T23:28:05Z")

</div>

谢谢，你们太棒了！

有个想法：我们能否利用返回的 `og:video`（包含 secure\_url、type、width 和 height）来显示一个视频播放器，就像 [通用引擎](https://github.com/discourse/onebox/blob/master/lib/onebox/engine/allowlisted_generic_onebox.rb#L362-L376) 那样？

---

<div class="post-metadata">

### Author: ![jamie.wilson](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/jamie.wilson/32/185466_2.png) [@jamie.wilson](https://meta.discourse.org/u/jamie.wilson)
#### Post date: [2021年一月15日 18:31 UTC](https://meta.discourse.org/t/instagram-tv-oneboxing/172784/6 "2021-01-15T18:31:57Z")

</div>

我们使用的是 Instagram oEmbed API 端点，该端点不返回媒体类型、视频文件 URL 或其他任何有助于构建带有嵌入式播放器的单框（onebox）的有用信息。

虽然直接访问该页面确实包含这些元数据，但如果在未认证的情况下多次（超过几次）访问，似乎会触发远程端的状态变化，导致其开始要求身份验证。这就是你首帖中的链接指向登录页面的原因。

就单框功能而言，目前看来我们在处理 IGTV 链接时能做的相当有限。

---

<div class="post-metadata">

### Author: ![renato](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/renato/32/383632_2.png) [@renato](https://meta.discourse.org/u/renato)
#### Post date: [2021年一月21日 02:24 UTC](https://meta.discourse.org/t/instagram-tv-oneboxing/172784/7 "2021-01-21T02:24:15Z")

</div>

使用 oEmbed API 会返回一个 `html` 属性，我注意到有一个[旧的讨论](https://meta.discourse.org/t/instagram-embed-plugin-is-it-possible/91222)提议使用这个返回的 `html`，但最终倾向于当前的解决方案。

我理解当前的方法更简洁、更安全，因此将其保留在核心中是合理的。

这并非我目前迫切需要的功能，但如果将来需要，是否可以通过自定义插件来实现这种“官方”的 Instagram 嵌入方式（强制固定高度，并回退到核心解决方案）？我能否为同一个 `matches_regexp` 添加另一个 Onebox 引擎，还是应该尝试对 `Onebox::Engine::InstagramOnebox` 进行猴子补丁（monkey patching）？

谢谢。

---

<div class="post-metadata">

### Author: ![jamie.wilson](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/jamie.wilson/32/185466_2.png) [@jamie.wilson](https://meta.discourse.org/u/jamie.wilson)
#### Post date: [2021年二月12日 20:39 UTC](https://meta.discourse.org/t/instagram-tv-oneboxing/172784/8 "2021-02-12T20:39:37Z")

</div>

> <https://github.com/discourse/onebox/blob/main/lib/onebox/engine/github_folder_onebox.rb#L13-L16>

`priority` 有助于控制哪些引擎匹配特定的 URL。

> <https://github.com/discourse/onebox/blob/main/lib/onebox/engine/reddit_media_onebox.rb#L47-L51>

此外，请注意 RedditMediaOnebox 所采用的方法。它会尝试返回自定义 HTML，但如果不知道如何处理特定 `type` 的结果，则会回退到通用的 onebox。
