标头中的 OpenGraph 前缀是否必要?

use*_*420 7 facebook-opengraph

我找到了很多方法来声明 opengraph。但哪一种是“正确”的方式?

http://ogp.me/在源代码中使用

<head prefix="og: http://ogp.me/ns#">
Run Code Online (Sandbox Code Playgroud)

但在示例中 html-tag 代替:

<html prefix="og: http://ogp.me/ns#">
Run Code Online (Sandbox Code Playgroud)

结合脸书看起来像

<html prefix="og: http://ogp.me/ns# fb: http://ogp.me/ns/fb#">
Run Code Online (Sandbox Code Playgroud)

或不带前缀

<html xmlns:og="http://ogp.me/ns#" xmlns:fb="http://ogp.me/ns/fb#">
Run Code Online (Sandbox Code Playgroud)

ogp.me 链接到 imdb 作为示例,以这种方式使用它

<html xmlns:og="http://ogp.me/ns#" xmlns:fb="http://www.facebook.com/2008/fbml">
Run Code Online (Sandbox Code Playgroud)

另一个网站设置 og:type "website" 或 "article" inline like

<html prefix="og: http://ogp.me/ns# fb: http://ogp.me/ns/fb# website: http://ogp.me/ns/website#">
Run Code Online (Sandbox Code Playgroud)

ogp.me 链接 zu a doc:https ://de.scribd.com/doc/30715288/The-Open-Graph-Protocol-Design-Decisions 见第 15 页;它说不要使用这种形式?

 xmlns:og="http://ogp.me/ns#" xmlns:fb="http://ogp.me/ns/fb#"
Run Code Online (Sandbox Code Playgroud)

这么多组合,其他网站什么都不做,只使用简单的元标签。声明是可选的还是应该以哪种形式使用?

Mal*_*voz 7

prefix="og: http://ogp.me/ns#"是开放图协议元标记所需的前缀。

xmlns是 XML 命名空间的一个属性,更多信息请参见:
开放图名称空间声明:带有 XMLNS 或 head 前缀的 HTML?


<html>您可以根据需要在or元素上设置它<head>,区别在于前缀的范围。将其限制为没有任何好处,<head>即使在大多数情况下您只会使用<meta>内部的相关标签<head>


您所看到的网站使用的前缀部分是,如果您想使用“fb:”而不是“og:”来扩展使用 Facebook 自己的属性。fb: http://ogp.me/ns/fb#"

请参阅:https ://developers.facebook.com/docs/sharing/opengraph/object-properties


这应该完全可以使用:

<html lang="{lang}" prefix="og: http://ogp.me/ns#">
  <head>
     ...
    <meta property="og:type" content="website"><!-- "og:type" can be omitted for 'website' (is default), required for other types: http://ogp.me/#types -->
    <meta property="og:url" content="https://example.com">
    <meta property="og:title" content="...">
    <meta property="og:description" content="...">
    <meta property="og:image" content="https://example.com/path/to/image.png">
    <meta property="og:image:type" content="image/png">
    <meta property="og:image:alt" content="...">
    <meta property="og:image:width" content="...">
    <meta property="og:image:height" content="...">
    <meta property="og:site_name" content="...">
  </head>
  ...
</html>
Run Code Online (Sandbox Code Playgroud)