我们有一个网站,我们希望用户根据他们的输入结果共享图像。基本上是一张地图,其中包含他们独有的选定国家。
直到今天,我们以前可以使用共享器.php参数来做到这一点,但现在这些参数似乎已经永远尘埃落定。它们原定于本月停产。
我们的替代方案(希望有人有更好的!(是根据URL参数动态地为我们的主页设置og:image属性(这是我们希望在FB帖子上链接的内容(。一切似乎都很简单,但是每当我们测试共享时,FB都会使用主页的标准图像,就好像没有URL参数一样。
有谁确切地知道FB在抓取网站以获取图像时是否使用URL参数?我们的测试似乎表明他们没有,但如果有人知道解决这个问题的方法,我将永远感激不尽。
仅供参考,这里是 og 标签,因此您可以看到它们是如何动态设置的。它是web2py,但我希望应该是有意义的:
<meta property="og:url" content="{{=cfg.global_base_url + request.env.web2py_original_uri}}" />
<meta property="og:type" content="website" />
<meta property="og:title" content="{{=(cfg.global_strap_line + ' | ' + cfg.global_app_name) if not response.title else response.title}}" />
<meta property="og:description" content="{{=cfg.global_open_graph_description if not response.description else response.description}}" />
<meta property="og:image" content="{{=cfg.global_share_image if not response.share_image else response.share_image}}" />
<meta property="og:locale" content="en_GB" />
下面是一个示例共享 URL:https://www.wherecani.live?pid=9d684d33-78ad-4f39-9010-458583dbfcef
您可以在 HTML 中看到 og:image 与 URL 参数相关,如预期的那样。
我遇到了同样的问题。这就是我修复它的方式。
这将显示默认图像L
<meta property="og:url" content="http:example.com">
<meta property="og:image" content="http:example.com/img/fb.jpg">
要动态更改基于 url 的图像,您还需要像这样添加og:url
<meta property="og:url" content="http:example.com/pages/cars">
<meta property="og:image" content="http:example.com/img/pages/cars/fb.jpg">
它对我有用。在开放图中进行测试。
这是另一种解释。