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

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

问题描述

我有一个页面,用户必须在该页面上对多个对象启动操作,但是Facebook的设计使用所需的meta属性标记将您限制为每页只有一个对象.

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.

但是,如果您希望用户在单击指向每个对象的链接时返回到SAME页面,则可以执行此操作,但这有点棘手...

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...

在对象页面上,在服务器上,查看传入的请求useragent.如果用户代理包含字符串'facebookexternalhit',则呈现HTML和OG标记-这就是Facebook抓取工具看到您的页面的方式.如果useragent不包含此字符串,请对您希望用户看到的页面执行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.

这就是您要这样做的方式:

And this is how you would do it:

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