【问题标题】:Replicate facebook open graph, how to get OG values on URL links复制 facebook 打开图,如何在 URL 链接上获取 OG 值
【发布时间】:2014-01-16 05:18:28
【问题描述】:

我想知道 facebook 如何从链接中提取打开的图形值。

<meta property="og:type" content="website">
<meta property="og:url" content="http://sample.com">
<meta property="og:title" content="sample title">
<meta property="og:description" content="sample description">

跨域是一个大问题,我认为如果链接只是在我的域上,我可以使用 AJAX 来实现。我也有这个想法通过&lt;iframe&gt; 像这样:

$('iframe').contents().find('meta[property=og:title]').attr("content");
//will output me: 'sample title'

但我还需要考虑 iframe 的加载/渲染时间,因此它不是最佳选择。任何帮助将不胜感激,谢谢。

PS。也有人可以告诉我 facebook 上支持的 og:type,这个链接好像坏了:https://developers.facebook.com/docs/reference/opengraph/object-type ;网站、博客、文章...?

【问题讨论】:

  • 我找到了这个插件:jQuery URLive。它使用 yql 和 ajax 来获取跨域的数据,因此不需要后端/代理页面,这很棒。

标签: javascript jquery facebook iframe meta-tags


【解决方案1】:

正如您正确指出的那样:跨域是这里的大问题。所以这不是通过 ajax 请求,而是通过您站点中的代理请求。比如你用php写一个页面:og.php。此页面将接收输入参数的 url,然后抓取 url 并以 json 格式返回 og。只有这样您的 javascript 才能获取此 json 并返回给用户。

iframe 也有跨域问题,所以你不能使用 iframe

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-03-04
    相关资源
    最近更新 更多