XFBML之类的按钮没有显示

时间:2012-04-24 07:25:14

标签: php

大家好日子,      我有类似按钮的问题。我跟踪了https://developers.facebook.com/docs/reference/plugins/like/中的每一步。我已经应用了一些我在网上找到的解决方案,包括附加的" https"在js.src中。代码可以在下面看到,我希望你能帮助我们。 ^^

<html 
    xmlns = "http://www.w3.org/1999/xhtml"
    xmlns:og = "http://ogp.me/ns#"
    xmlns:fb="http://ogp.me/ns/fb#">

    <?php
        $title = "This is a Title.";
        $type = "movie";
        $url = "http://www.200909630.site11.com/share.php";
        $image = "http://i3.kym-cdn.com/photos/images/original/000/264/615/242.png";
        $description = "This is a description.";
    ?>          

    <head>
        <title>Fund My Travel</title>
        <meta property = "og:title" name = "title" content = "<?php echo $title; ?>" />
        <meta property = "og:type" name = "type" content = "<?php echo $type; ?>" />
        <meta property = "og:url" name = "url" content = "<?php echo $url; ?>" />
        <meta property = "og:image" name = "image" content = "<?php echo $image;; ?>" />
        <meta property = "og:description" name = "description" content = "<?php echo $description; ?>" />
        <script type = "text/javascript" src = "http://static.ak.fbcdn.net/connect.php/js/FB.Share"></script>
        <script type = "text/javascript">
            var buttons = document.getElementsByName('fb_share');
            var count = buttons.length;
            for(var i = 0; i<count; i++) {
                var data = FB.Share.getUrl(buttons[i]);
                if(FB.Share.results[data]) {
                    buttons[i].fb_count = FB.Share.results[data].total_count;
                }
                FB.Share.displayBox(buttons[i], 0);
            }
        </script>
        <script>
            !function(d, s, id) {
                var js, fjs = d.getElementsByTagName(s)[0];
                if( !d.getElementById(id) ) {
                    js = d.createElement(s);
                    js.id = id;
                    js.src = "//platform.twitter.com/widgets.js";
                    fjs.parentNode.insertBefore(js, fjs);
                }
            }
            (document, "script", "twitter-wjs");
        </script>
        <script type="text/javascript">
            window.___gcfg = {lang: 'en-GB'};
            (function() {
                var po = document.createElement('script'); po.type = 'text/javascript'; po.async = true;
                po.src = 'https://apis.google.com/js/plusone.js';
                var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(po, s);
            })();
        </script>
    </head>
    <body>
        <div id = "fb-root"></div>
        <script>
            (function(d, s, id) {
                var js, fjs = d.getElementsByTagName(s)[0];
                if (d.getElementById(id)) return;
                js = d.createElement(s); js.id = id;
                js.src = "//connect.facebook.net/en_US/all.js#xfbml=1";
                fjs.parentNode.insertBefore(js, fjs);
            }(document, 'script', 'facebook-jssdk'));
        </script>

        <table cellspacing = "3" cellpadding = "3">
            <tr>
                <fb:like send = "false" width = "450" show_faces = "false"></fb:like>
            </tr>
            <tr>
                <td>
                    <a name = "fb_share"></a>
                </td>
                <td>
                    <a href = "https://twitter.com/share" class = "twitter-share-button" data-lang = "en"
                        data-url = "<?php echo $url; ?>" data-text = "<?php echo $title; ?>"></a>
                </td>
                <td>
                    <g:plusone size = "medium"></g:plusone>
                </td>
            </tr>
        </table>
    </body>
</html>

2 个答案:

答案 0 :(得分:0)

<div id="fb-root"></div>
<script>(function(d, s, id) {
var js, fjs = d.getElementsByTagName(s)[0];
if (d.getElementById(id)) return;
js = d.createElement(s); js.id = id;
js.src = "//connect.facebook.net/en_US/all.js#xfbml=1";
fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));</script>
 initialize this script after body tag not before than, than put this div where you want that button and inser your url of page to like in data-href .
 <div class="fb-like" data-href="http://stackoverflow.com/questions/10293545/strange-      error-headers-already-sent-by-output-started-at" data-send="true" data-width="450" data-show-faces="true"></div>

答案 1 :(得分:0)

 <script>
   window.fbAsyncInit = function() {
    FB.init({
  appId      : 'YOUR_APP_ID', // App ID
  channelUrl : '//WWW.YOUR_DOMAIN.COM/channel.html', // Channel File
  status     : true, // check login status
  cookie     : true, // enable cookies to allow the server to access the session
  xfbml      : true  // parse XFBML
});

// Additional initialization code here
};

  // Load the SDK Asynchronously
    (function(d){
 var js, id = 'facebook-jssdk', ref = d.getElementsByTagName('script')[0];
 if (d.getElementById(id)) {return;}
 js = d.createElement('script'); js.id = id; js.async = true;
 js.src = "//connect.facebook.net/en_US/all.js";
 ref.parentNode.insertBefore(js, ref);
 }(document));
</script>

尝试在head标签中添加javascript sdk