打开图 og:video 元标签内容
我正在尝试建立一个页面,当它被共享/喜欢时,它可以被 Facebook 正确地抓取。该页面将有一个与之关联的 YouTube 视频,因此在 og:video 标签的内容属性中,我应该放置 YouTube 视频嵌入链接还是实际的 YouTube 页面链接,以便它通过小“预览”按钮显示在 Facebook 上在 Facebook 上播放视频?
希望有人可以帮忙!谢谢!
I'm trying to set up a page which can be properly scraped by Facebook when it's shared/liked. The page will have a YouTube video associated with it, so in the content attribute of the og:video tag, should I put the YouTube video embed link or the actual youtube page link for it to appear on Facebook with the little "Preview" button that plays the video in Facebook?
Hope someone can help! Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
你有两个选择。您可以将
og:video
设置为 https://www.youtube.com /v/YOUTUBECODE 或将og:url
设置为 YouTube 页面。在我的示例中,我嵌入了此视频 https://www.youtube.com/v/BQBjVr1iHH4 在以下页面 https://www.keithandthegirl .com/vip/bonus/episode/9/40/this-is-40。我希望每当有人在 Facebook 上分享我的页面时,Facebook 都会显示 YouTube 视频。
选项 1:将
og:video
设置为 https://www. youtube.com/v/YOUTUBECODE元标记如下所示
请注意,YouTube URL 的结构与典型 URL 不同。您需要将“v”查询与 YouTube 链接隔离开来,并以我上面展示的
og:video
链接格式使用它。在我的示例中,v
的值为BQBjVr1iHH4
。选项 2:将
og:url
设置为 YouTube 页面。如果您无法隔离
v
代码,您可以将og:url
标记设置为 YouTube 页面。在我的示例中,它看起来像这样:这将告诉 Facebook 从 https 获取 Open Graph 标签: //www.youtube.com/watch?v=BQBjVr1iHH4 并在嵌入中使用它。这意味着描述和标题将来自 YouTube 页面。但是,如果有人点击该链接,他们就会访问您的网站。
在我的示例中,如果有人在我使用第二个选项时粘贴以下链接 https://www.keithandthegirl.com/vip/bonus/episode/9/40/this-is-40 Facebook 将看到 URL 设置为 YouTube,并查询该 YouTube 链接以获取 OG 信息。一切看起来都像 YouTube 除了链接将点击到 https://www.keithandthegirl.com/vip/bonus/episode/9/40/this-is-40
另一项注意事项:请务必使用 https ,而不是 http。 Facebook 不会在网站上嵌入任何不安全的视频。
You have two options. You can either set the
og:video
to https://www.youtube.com/v/YOUTUBECODE or set theog:url
to the YouTube page.In my examples, I'm embedding this video https://www.youtube.com/v/BQBjVr1iHH4 in the following page https://www.keithandthegirl.com/vip/bonus/episode/9/40/this-is-40. I would like Facebook to show the YouTube video whenever anyone shares my page on Facebook.
Option 1: setting the
og:video
to https://www.youtube.com/v/YOUTUBECODEThe meta tag will look like
Notice the structure of the YouTube URL is different than the typical URL. You will need to isolate the "v" query from the YouTube link and use it in the
og:video
link format I showed above. In my example, the value ofv
isBQBjVr1iHH4
.Option 2: setting the
og:url
to the YouTube page.If you don't have the ability to isolate the
v
code, you can set theog:url
tag to the YouTube page. In my example, it would look like this:This will tell Facebook to get the Open Graph tags from https://www.youtube.com/watch?v=BQBjVr1iHH4 and use that in the embed. That means the description and title will come from the YouTube page. However, if someone clicks the link, they'll go to your website.
In my example, if someone pastes the following link while I use the second option https://www.keithandthegirl.com/vip/bonus/episode/9/40/this-is-40 Facebook will see the URL is set to YouTube and query that YouTube link for the OG info. Everything will look like YouTube except the link will click to https://www.keithandthegirl.com/vip/bonus/episode/9/40/this-is-40
One other note: make sure to use https, not http. Facebook will not embed any non-secure video on the site.
以下是我的发现:
使用 Facebook 的开放图谱协议,发布者现在可以使用来自任何 URL 的任何视频,只要该 URL 在其 HTML 的
中具有正确格式的元数据。以下是
中应包含的信息列表:
缩略图的 URL:
视频文件 URL(例如 SWF、MP4、..):
您页面的 URL:
标题:
描述:
视频像素宽度:
视频像素高度:
内容类型:
Here's what I found:
Using Facebook's Open Graph Protocol, Publisher can now use any video from any URL, as long as the URL has correctly formatted metadata in the
<head>
of its HTML. Here's the list of information that should be in the<head>
:Thumbnail image's URL:
Video file URL (e.g. SWF, MP4, ..):
Your page's URL:
Title:
Description:
Video pixel width:
Video pixel height:
Content Type:
您可以从 YouTube 页面的源代码中看到,
og:video
标记的格式如下您还可以在以下 URL 的源代码中看到简化的 YouTube 使用的元数据示例: http://fb.stevelarsen.co.uk/example.html
您可以在此处阅读有关 Open Graph 协议的更多信息:http://ogp.me/
You can see from the source code of a YouTube page, the
og:video
tag is in the following formatYou can also see an example of the metadata used from YouTube simplified in the source code of the following URL: http://fb.stevelarsen.co.uk/example.html
You can read more about the Open Graph protocol here: http://ogp.me/
.flv 文件的链接......查看 https://developers.facebook。 com/docs/opengraph/#types
The link of the .flv file.... check out https://developers.facebook.com/docs/opengraph/#types
对于那些偶然发现 facebook 提供的调试器的人,请注意以下事项:
当您登录到调试器时,您处于 https 会话下。为了在调试中看到您的视频,您需要在元中添加视频的安全网址。添加 YouTube 视频很简单,只需将页面 url 放入 og:url 即可。
花了一个小时才得出这个结论。太晚了,我太累了,现在想睡觉:)
For those who stumbled at the debugger provided by facebook please note the following:
When you are logged into the debugger you are under https session. In order to see your video in the debugging you need to add the secure url for video in meta. Adding youtube videos is easy, simply put the page url in og:url and it will work.
Spent and hour to come to this conclusion. Its too late I am too tired, wanna sleep now :)
我想通了。我查看了 Collegehumor.com 是如何做到这一点的,它们包含了 Facebook API 中未提及的一堆内容。而不仅仅是以下内容:
您还需要
link rel="video_src"
并且拥有videothumbnail
和og:image
也会有所帮助 - 我'我不太确定是谁干的,但你就知道了。这有效:)I figured it out. I had a look at how Collegehumor.com does it and they include a bunch of stuff not mentioned in the Facebook API. Rather than just the following:
you also need
link rel="video_src"
and it helps to havevideothumbnail
andog:image
too - I'm not entirely sure which one did it but there you go. That works :)