首页 文章

使用sharer.php方法动态Facebook共享页面

提问于
浏览
0

我创建Facebook分享按钮的方法是: 1. create a share.php (facebook capture meta data in this fake website and redirect to the actual website i want to share

<!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. The data need in share.php is passed from main page

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');

问题是, what should be the og:url ?有两个链接:share.php和我想要分享的实际网站,

If I use share.php?title=...&description=.. , I still have to specific url ,这很奇怪:它将是share.php?url = share.php?url = share.php,最终我仍然无法引用正确的网址进行分享

If I use the actual website ,它无法收集任何元数据,因为我的想法是所有meta都在share.php上

如何解决问题?谢谢

!!!!!!!!!!!!!!!Updated on 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主页上的图像会显示并存在于我的共享内容中 .

为什么会发生这种情况,是否由防火墙的某些错误设置引起?谢谢

4 回答

  • 2

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

  • 0

    og:url 应该是包含元数据的网站 - 在这种情况下,您应该使用重定向和元数据或参考 share.php?url=the_url 创建网站 .

  • 2

    我想你只是被 og:url 参数误导了:

    og:url-对象的规范URL,将用作图中的永久ID

    听起来完全合法,但是:当您指定该参数时,Facebook会从该URL获取元数据,而不是从当前页面获取 . 这就是您将引用的URL放在那里时没有元数据的原因 . 还有那令人讨厌的原因 share.php?url=share.php?url=share.php... .

    您要做的是使用 href 属性完成:https://developers.facebook.com/docs/reference/plugins/like/

    我不确定你在构建什么,但也许这样你甚至可以将共享按钮集成到你重定向到的页面中 . 然后你仍然设置那个伪元数据页面,然后把它扔进那个(以前重定向到)页面的 og:url 然后:)

  • 1

    你可以按照演示,祝你好运 .

    http://www.kimwoodbridge.com/how-to-create-your-one-facebook-share-url/

    顺便说一句,在你测试新的方式之前 . 你最好清楚fb的会话 . http://developers.facebook.com/tools/debug/og/object?q=http://yourwebsite.com

相关问题