Facebook autoshare wordpress插件?

时间:2013-01-13 15:25:09

标签: javascript facebook

我试图找到一个要求访问Facebook应用程序的插件,如果您确认,那么您访问的每个帖子都应自动发布到用户墙中。我在几个页面上看过这个例子:www.hajgare.com,www.flej.eu 由于我还没有找到任何东西,我已经开始自己构建它,这是我到目前为止所做的:检查用户是否登录到facebook并检查他是否已批准该应用程序。如果是,则显示facebook分享框(www.balkanews.net点击任何新闻)。

我的问题是如何在不显示facebook分享框的情况下分享。

<div id="fb-root"></div>
<script type="text/javascript">
        $(function() {
            var e = document.createElement('script');
            e.type = 'text/javascript';
            e.src = document.location.protocol +
            '//connect.facebook.net/de_DE/all.js';
            e.async = true;
            document.getElementById('fb-root').appendChild(e);
        }());

            $(function(){

                liked = true;
                $("#trigger").click(function(){
                    if(liked){
                        post();
                    }else{
                        //alert('{L_FIRST_CLICK_LIKE}');
                        alert('like');
                    }
                });
            });


            window.fbAsyncInit = function() {
                FB.Event.subscribe('edge.create', function(response) {
                    <!-- IF BOTH -->
                    liked = true;
                    <!-- ELSE -->
                    release();
                    <!-- ENDIF -->
                }); 
                FB.Event.subscribe('edge.remove', function(response) {
                    window.location.reload();
                });
            };
        <!-- ENDIF -->

        function release() {
            $("#item_container").hide();
            $("#real_container").show();
        }

        function post(){

            FB.init({appId: "409010965841527", status: true, cookie: true,        xfbml: true});
            FB.ui({
                    method: 'feed',
                    link:   document.URL,
                }, callback);
            setTimeout('move()', 100);
        }

        function callback(response) {
            if(response && response.post_id){
                release();
            }
        }

        function move(){
            $(".fb_dialog").css("left", "38px");
            setTimeout('move()', 400);
        }
    </script>

 <!- ///////////// -->
 <a href="javascript:;" id="trigger"><img src="./template/images/share.png" alt="" /></a>
 <script>
 window.fbAsyncInit = function() {

FB.init({appId: '409010965841527', status: true, cookie: true,
         xfbml: true});

FB.getLoginStatus(function(o) { 
   if (!o && o.status) return;
   if (o.status == 'connected') {
    //here goes the post code
    post();

   } else if (o.status == 'not_authorized') {
      window.location = 'https://www.facebook.com/dialog/oauth/?client_id=409010965841527&redirect_uri='+document.URL+'/&scope=user_about_me,publish_actions,user_likes';

   } else {
     window.location = 'https://www.facebook.com/dialog/oauth/?client_id=409010965841527&redirect_uri='+document.URL+'/&scope=user_about_me,publish_actions,user_likes';
   }
});

};

 (function() {
var e = document.createElement('script'); e.async = true;
e.src = document.location.protocol +
  '//connect.facebook.net/en_US/all.js';
document.getElementById('fb-root').appendChild(e);
}());
</script>

1 个答案:

答案 0 :(得分:0)

您的代码很好,但您正在执行错误的Facebook发布操作 然后不要使用FB.ui 使用Fb.Api来解​​决你的proplem示例代码

 function postToFacebook() {
    var body = 'Reading Connect JS documentation';

    FB.api('/me/feed', 'post', { body: body ,message: 'I visited this post ' , link:'<?php echo wp_get_shortlink(get_the_ID()); ?>'}, function(response) {
      if (!response || response.error) {
        window.location = 'https://www.facebook.com/dialog/oauth/?client_id=409010965841527&redirect_uri='+document.URL+'/&scope=user_about_me,publish_actions,user_likes'; 
      } else {
        alert('Post published '); // you can del this alert 
      }
    });
}

那就是它 如果此代码适用于您并发布您的最终代码,请告诉我