如何将Facebook的Open Graph集成到Meteor应用程序中? [英] How to integrate Facebook's Open Graph in a Meteor application?

查看:63
本文介绍了如何将Facebook的Open Graph集成到Meteor应用程序中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将Meteor应用程序与Facebook Open Graph集成在一起,以便在时间轴上发布操作.

I'm trying to integrate my Meteor application with Facebook Open Graph, to publish actions in the timeline.

Facebook API通过在HTML头中定义特定于对象的元标记来工作,该元标记将由API读取.例如:

Facebook API works by defining object specific meta tags in the HTML head, that will be read by the API. For example:

<head prefix="og: http://ogp.me/ns# [YOUR_APP_NAMESPACE]: 
                     http://ogp.me/ns/apps/[YOUR_APP_NAMESPACE]#">
    <title>OG Tutorial App</title>
    <meta property="fb:app_id" content="[YOUR_APP_ID]" /> 
    <meta property="og:type" content="[YOUR_APP_NAMESPACE]:recipe" /> 
    <meta property="og:title" content="Stuffed Cookies" /> 
    <meta property="og:image" content="http://fbwerks.com:8000/zhen/cookie.jpg" /> 
    <meta property="og:description" content="The Turducken of Cookies" /> 
    <meta property="og:url" content="http://fbwerks.com:8000/zhen/cookie.html">
</head>

但是,Facebook API在检查任何URL时看到的内容如下:

However, what Facebook API sees when inspecting any URL is something like this:

<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="/ed99236548322b46a7562b49cd6ee0e0f059e506.css">
  <script type="text/javascript" src="/c16ff21884b1f831d91ebf271236ef78b03b552e.js"></script>
  <title>Made with Meteor!</title>
</head>
<body>
</body>
</html>

在Meteor应用程序中集成此元标记的最佳方法是什么,该标记可能会随URL的变化而变化?

What is the best way of integrating this meta tags, that may change depending on the URL, in the Meteor application?

推荐答案

我遇到了同样的问题.

两种处理方法:

  • 最近在"spiderable"包中添加了新内容(当前在"devel"分支中),还可以更改客户端代码中的"head"标签 (附加og:title等.),从服务器将其神奇地"投放到Facebook .
  • A recent addition to the "spiderable" package (currently in "devel" branch) also lets you change the "head" tag in client code (append your og:title etc..) and have that "magically" served to Facebook from your server.

(注意:您可能需要在此解决方案中不使用自动发布程序包,因为"spiderable"会在依靠"autopublish"设置为"true"的标志的同时停止页面渲染客户端启动)

(NOTE: you will probably need to not use autopublish package with this solution, since "spiderable" stops the page rendering while relying on a flag that "autopublish" sets to "true" right on client startup)

  • 更轻巧的解决方案是Meteor的头包":

https://github.com/ayal/headly

安装后,您可以像这样使用它:

After installation you use it like so:

Meteor.headly.config({tagsForRequest: function(req) {
  ... do something dynamic here, i.e get title from db based on url param ...
  return '<meta property="og:title" content="<DYNAMIC TITLE>" />';
}});

这篇关于如何将Facebook的Open Graph集成到Meteor应用程序中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆