简体   繁体   English

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

[英]Dynamic facebook share page using sharer.php approach

My way to create a facebook share button is : 1. create a share.php (facebook capture meta data in this fake website and redirect to the actual website i want to share ) 我创建一个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. The data need in share.php is passed from main page 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');

The problem is , what should be the og:url ? 问题是, og:url应该是什么 There are two link : the share.php and the actual website I want to share, 有两个链接:share.php和我要共享的实际网站,

If I use share.php?title=...&description=.. , I still have to specific url and that is weird : it will be share.php?url=share.php?url=share.php and eventually I still can not reference the correct url for sharing 如果我使用share.php?title = ...&description = ..,我仍然必须指定特定的URL ,那很奇怪:它将是share.php?url = share.php?url = share.php,最终我仍然无法引用正确的网址进行共享

If I use the actual website , it can not collect any meta data, as my idea is all meta is on share.php 如果我使用实际的网站 ,则它无法收集任何元数据,因为我的想法是所有元数据都位于share.php上

How to fix the problem ? 如何解决该问题? thanks 谢谢

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

I figured out the root problem , it is caused by different source of image: 我发现了根本问题,它是由不同的图像来源引起的:

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

This image is capture by facebook on share page as expected, working flawlessly. 这张图片是Facebook在共享页面上按预期方式捕获的,可以正常工作。

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

This image ,hosted in my server , however, is not not shown on the share page as for the first time, but only when I reload the page. 但是,托管在我的服务器中的该映像第一次没有显示在共享页面上,而是仅在重新加载页面时才显示。 * Although it is not shown on the share page, the image is shown and exist on my share content in my facebook homepage. *尽管它没有显示在共享页面上,但是图像显示并存在于我的Facebook主页上的共享内容中。

Why is that happen , is it caused by some incorrect settings of firewall? 为什么会发生这种情况,这是由于防火墙的某些错误设置引起的吗? thanks 谢谢

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

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

I think you only have been misled by the og:url parameter: 我认为您只是被og:url参数所误导:

og:url - The canonical URL of your object that will be used as its permanent ID in the graph og:url对象的规范URL,将在图形中用作其永久ID

Sounds totally legit, but : When you specify that parameter, Facebook fetches the meta data from that URL instead from the current page. 听起来完全合法, 但是 :当您指定该参数时,Facebook从该URL而不是从当前页面获取元数据。 This is why you have no meta data when you put the referred URL there. 这就是为什么将引用的URL放在那里时没有元数据的原因。 And also the reason for that nasty share.php?url=share.php?url=share.php... . 以及该讨厌的share.php?url=share.php?url=share.php...

What you are trying to do is done using the href attribute: https://developers.facebook.com/docs/reference/plugins/like/ 您尝试使用href属性完成操作: https : //developers.facebook.com/docs/reference/plugins/like/

I'm not sure what you are building, but maybe this way you even can integrate the share button into the page that you redirect to. 我不确定您要构建的内容,但是也许通过这种方式,您甚至可以将共享按钮集成到您重定向到的页面中。 Then you still set up that fake meta data page and just throw it into og:url in that (formerly redirected to) page then :) 然后,您仍然要设置该伪造的元数据页面,然后将其放入该页面(以前重定向到)的og:url中,然后:)

you can follow the demo,wish you gook luck. 您可以按照演示进行操作,祝您好运。

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

by the way,before you test new way. 顺便说一下,在测试新方法之前。 you had better clear the fb's session. 您最好清除fb的会话。 http://developers.facebook.com/tools/debug/og/object?q=http://yourwebsite.com http://developers.facebook.com/tools/debug/og/object?q=http://yourwebsite.com

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM