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

查看:22
本文介绍了如何将 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?

推荐答案

我遇到了同样的问题.

解决这个问题的两种方法:

Two ways to deal with this:

  • 最近添加到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.

(注意:您可能需要在此解决方案中不使用 autopublish 包,因为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 的headly"包:

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天全站免登陆