php - 使用 sharer.php 方法的动态 facebook 共享页面

标签 php javascript facebook facebook-opengraph

我创建 Facebook 分享按钮的方法是: 1.创建一个 share.php (facebook 捕获这个假网站中的元数据并重定向到我想要分享的实际网站)

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:fb="https://www.facebook.com/2008/fbml">
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <title><?php echo $_GET['title'];?></title>
        <meta property="og:url" content="<?php echo $_GET['url'];?>" />
        <meta property="og:title" content="<?php echo $_GET['title'];?>" />
        <meta property="og:description" content="<?php echo $_GET['title'];?> "/>
        <? 
        if (isset($_GET['leftImg']) && $_GET['leftImg'] != 'undefined') {
            echo '<meta property="og:image" content="'.$_GET['leftImg'].'"/>';
        }
        if (isset($_GET['rightImg']) && $_GET['rightImg'] != 'undefined') {
            echo '<meta property="og:image" content="'.$_GET['rightImg'].'"/>';
        }
        ?>
    </head>
    <body>
        <script>
            window.location.href = "<?php echo $_GET['redirect'];?>";
        </script>
    </body>

</html>

<强>2。 share.php中需要的数据是从主页传递过来的

 window.open('http://www.facebook.com/sharer.php?u=' + encodeURIComponent('http://' + window.location.hostname + '/share.php?url=http://yahoo.com&title=test&redirect=..&leftImg=......&' ),'sharer','toolbar=0,status=0,width=826px,height=536');

问题是,og:url 应该是什么?有两个链接:share.php 和我想分享的实际网站,

如果我使用 share.php?title=...&description=.. ,我仍然需要特定的 url 这很奇怪:它将是 share.php?url=share.php ?url=share.php 最终我仍然无法引用正确的共享网址

如果我使用实际网站,它无法收集任何元数据,因为我的想法是所有元数据都在 share.php

如何解决这个问题?谢谢

!!!!!!!!!!!!!!!更新于 11/4/2013:!!!!!!!!!!!!!!!

我找到了根本问题,它是由不同的图像源引起的:

eg. http://www.tekxon.com.pk/sites/all/themes/bluemasters/images/gallery/3.jpg

这张图片是由 Facebook 在共享页面上按预期捕获的,工作完美。

eg. http://54.251.107.161/source/test2/2012/05/07/0/3/A/Content/15/Pg015.png 

但是,托管在我的服务器中的该图像第一次不会显示在共享页面上,而是仅在我重新加载页面时显示。 * 虽然没有显示在分享页面上,但该图像会显示并存在于我的 Facebook 主页的分享内容中。

为什么会出现这种情况,是否是防火墙设置不正确造成的?谢谢

最佳答案

og:url 应该是您要重定向到的网站

关于php - 使用 sharer.php 方法的动态 facebook 共享页面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15214144/

相关文章:

javascript - Codeigniter Ajax 发布 : Always Return Same Data

php - 如何将子值添加到新数组?

php - 是否可以在 codeigniter 的助手中使用多个 $this

android - SmartLock 无需询问即可保存 Facebook 凭据

javascript - 我可以让 AngularJS 为 Facebook OpenGraph 抓取工具使用不同的 Controller 吗?

php - 用户在 Facebook 上注销,JS SDK 停止工作

php - 如何在 PHP 中查找 Windows 和 Linux 上的用户主目录

javascript - Redux/Thunk 中的递归函数返回 Promise 对象,而不是常规对象

javascript - preg_match 的 JavaScript 等价物是什么?

javascript - MongoDB函数——引用集合和更新值