我正在尝试向我正在开发的 AngularJs 应用程序添加开放图形功能。我希望我的应用程序的用户与他们的 Facebook 好友共享一个 URL。我了解要共享工作,您需要向页面添加开放图元数据标签(url、描述、图像、标题等)。我需要我的用户共享的 URL 是动态的并且具有以下结构:
http://example.com/game/invitation/1118
其中 1118 是要分享的游戏 ID。下面的文章描述了在 Angular 应用程序中启用社交共享:
http://www.michaelbromley.co.uk/blog/171/enable-rich-social-sharing-in-your-angularjs-app
然而,这篇文章指出,Facebook 爬虫无法呈现动态内容。因此,当Facebook爬虫访问http://example.com/game/invitation/1118时,我需要将请求重定向到我的服务器以生成正确的开放图元标记。我正在使用 IIS(文章解释了如何通过 Apache 执行此操作)。这是我的重写规则:
<rule name="Imported Rule 1" stopProcessing="true">
<match url="invitation/([_0-9a-z-]+)" ignoreCase="false" />
<conditions>
<add input="{HTTP_USER_AGENT}" pattern="facebookexternalhit/[0-9]|Twitterbot|Pinterest|Google.*snippet" />
</conditions>
<action type="Redirect" url="http://meta.example.com/social/meta/{R:1}" appendQueryString="false" />
</rule>
因此,每当 url 包含邀请/[游戏 ID] 并且用户代理是 Facebook(或 Twitter、Pinterest、Google 等)时,将它们重定向到“http://meta.example.com/social/meta/[id]”。这很好用。我已经设置了一个单独的网站 ( http://meta.example.com ) 来呈现开放图元标记,供爬虫索引。
问题是我需要使用 http://example.com/game/invitation/1118作为 og:url 元标记值(这是用户的 friend 点击查看邀请的链接,我用户的大多数 friend 不会是 Facebook 爬虫)。如果我包括
<meta property="og:url" content="http://example.com/game/invitation/1118" />
在 http://meta.example.com/social/meta/1118 生成的页面中,然后我在 Facebook 的 Open Graph Object Debugger 中收到循环引用错误。 Facebook 的爬虫正在从 http://meta.example.com/social/meta/1118 中生成的元标签中挑选出标题、描述等。 .不过好像是挑出来了http://example.com/game/invitation/1118来自 og:url 元标记并再次重新运行它。据我所知,这会导致循环引用。
那么,如何配置 IIS 来重定向对 http://example.com/game/invitation/1118 的请求?至 http://meta.example.com/social/meta/1118当用户代理是 Facebook 时,以便生成适当的开放图元标记并重用启动此过程的原始 URL (http://example.com/game/invitation/1118)?
上面的文章 ( http://www.michaelbromley.co.uk/blog/171/enable-rich-social-sharing-in-your-angularjs-app) 提到了如何为 Apache 执行此操作。我不知道如何将其转换为 IIS:
The [P] flag causes Apache to perform a remap using mod_proxy and mod_proxy_http, rather than a regular redirect. If a 301 redirect is used, Facebook for example will link to the “static-page.php” URL rather than the original URL.
感谢您的帮助。我正在使用 IIS 8。
最佳答案
而不是重定向操作:
<action type="Redirect" url="http://meta.example.com/social/meta/{R:1}" appendQueryString="false" />
你应该使用重写操作:
<action type="Rewrite" url="/social/meta/{R:1}" appendQueryString="false" />
请注意,您应该在同一域中使用相对路径。
关于angularjs - facebook open graph 和 AngularJs,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27793799/