Open Graph protocol允许任何web页面成为社交网络图中的富对象。例如,在facebook上用于允许任何网页具有与facebook其他对象相同的功能。
要将网页转换为图形对象,需要向网页中添加基本元数据,在web页面的<head>中放置额外的<meta>标记。每页所需的四个属性是
og:title—显示的标题,例如“the rock”。
og:type-对象的类型,例如“video.movie”。
og:image-缩略图的url。
og:url-对象的规范url,将在图中用作其永久id,例如“http://www.imdb.com/title/tt0117500/”。
示例:
<html prefix="og: http://ogp.me/ns#">
<head>
<title>The Rock (1996)</title>
<meta property="og:title" content="The Rock" />
<meta property="og:type" content="video.movie" />
<meta property="og:url" content="http://www.imdb.com/title/tt0117500/" />
<meta property="og:image" content="http://ia.media-imdb.com/images/rock.jpg" />
...
</head>
...
</html>
以下属性对于任何对象都是可选的,通常建议使用:
og:audio—音频文件的URL。
og:video-视频文件的URL。
og:description-对象的描述信息。
og:determiner-出现在句子中这个对象的标题之前的单词。枚举(a, an, the, "", auto)。如果选择“auto”,则数据的使用者应在“a”或“an”之间进行选择。默认为""(空白)。
og:locale-区域设置。格式language_TERRITORY
. 默认值为en_US
。
og:locale:alternate-此页可用于的其他区域设置的数组。
og:site_name-整个网站的名称。
示例:
<meta property="og:audio" content="http://example.com/bond/theme.mp3" />
<meta property="og:description"
content="Sean Connery found fame and fortune as the
suave, sophisticated British agent, James Bond." />
<meta property="og:determiner" content="the" />
<meta property="og:locale" content="en_GB" />
<meta property="og:locale:alternate" content="fr_FR" />
<meta property="og:locale:alternate" content="es_ES" />
<meta property="og:site_name" content="IMDb" />
<meta property="og:video" content="http://example.com/bond/trailer.swf" />