同一页面上的多个 Facebook opengraph 对象 [英] Multiple Facebook opengraph objects on the same page

查看:31
本文介绍了同一页面上的多个 Facebook opengraph 对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个页面,用户必须在其中对多个对象启动操作,但 Facebook 的设计使用所需的元属性标签将您限制为每个页面只能有一个对象.

I have a page where users must initiate actions on multiple objects, but Facebooks design limits you to just one object per page using the required meta property tags.

有没有人找到解决这个问题的方法?

Has anyone found a solution to this problem?

推荐答案

Open Graph 使用 URL 作为对象标识符,因此不可能在一个页面上有多个对象,页面对象.

The Open Graph uses the URL as the object identifier, so its not possible to have several objects on one page, the page is the object.

相反,您需要为每个对象提供一个 URL,并且该 URL 的 HTML 应包含正确的 OG 标记.

Instead, you'll need a URL for each object, and that URL's HTML should contain the correct OG markup.

您可以在一个页面上放置多个点赞按钮,并通过为每个点赞按钮指定 'href' 参数使它们指向您的每个对象.

You can put multiple like buttons on one page, and make them point at each of your objects by specifying the 'href' parameter for each like button.

但是,如果您希望用户在单击每个对象的链接时最终返回相同的页面,您可以这样做,但它有点棘手...

However, if you want the user to end up back at the SAME page when they click on the link to each of these objects, you can do this, but its a bit tricksy...

在您的对象页面上,在您的服务器上,查看传入的请求用户代理.如果用户代理包含字符串facebookexternalhit",则呈现 HTML 和 OG 标记 - 这就是 Facebook 抓取工具如何查看您的页面.如果用户代理不包含此字符串,则执行 302 重定向到您希望用户看到的页面.

On your object pages, on your server, look at the incoming request useragent. If the useragent contains the string 'facebookexternalhit' then render the HTML and the OG markup - this is how the Facebook scraper sees your page. If the useragent does not contain this string, perform a 302 redirct to the page you want the user to see.

结果?许多对象,但只有一个用户可见的页面.赢了.

Result? Many objects, but only one user-visible page. Win.

这就是你要做的:

<?php

if ($_SERVER["HTTP_USER_AGENT"] != "facebookexternalhit/1.1 (+http://www.facebook.com/externalhit_uatext.php)") {
    redirect('http://www.somesite.com', 302);
}
function redirect($url, $type=302) {
    if ($type == 301) header("HTTP/1.1 301 Moved Permanently");
    header("Location: $url");
    die();
}

?>

<html...

这篇关于同一页面上的多个 Facebook opengraph 对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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