【问题标题】:Facebook Share callback not workingFacebook 分享回调不起作用
【发布时间】:2015-03-20 22:37:49
【问题描述】:

我正在尝试设置一个包含共享按钮的 Facebook 页面标签应用程序。它可以很好地显示共享对话框,但没有调用回调。如果我将 FB.ui 函数放在 window.fbAsyncInit 函数中,那么回调会很好。但是,这样做会使共享窗口出现在页面加载时。我想让它显示在单击按钮上。我尝试仅在单击按钮后调用 window.fbAsyncInit 函数,但这也不起作用。这是我页面的完整 HTML:

   <html>
   <head>

   </head>
   <body style="background-color:#9ec64e;">
       <div id="fb-root"></div>


          <table style="width:100%">
              <tr><td>
                  <br>
          <h1>Press button to share</h1>
                </td>
                <td>
                    <p id="enterButton"><a href='' onclick="showShare();"><img src='share_btn.png' style='width:200px;'></a></p>
                </td>
            </tr>
        </table>

          <script>
        function showShare() {
            console.log("showShare");
           FB.ui(
             {
               method: 'feed',
               name: 'Facebook Dialogs', // name of the product or content you want to share
               link: 'https://developers.facebook.com/docs/reference/dialogs/', // link back to the product or content you are sharing
               picture: 'http://fbrell.com/f8.jpg', // path to an image you would like to share with this content
               caption: 'Reference Documentation', // caption
               description: 'Dialogs provide a simple, consistent interface for applications to interface with users.' // description of your product or content
             },
             function(response) {
                 console.log("finished");
               if (response && response.post_id) {
                 alert('Post was published.');
               } else {
                 alert('Post was not published.');
               }
             }
           );
        }
       window.fbAsyncInit = function() {
           // init the FB JS SDK
            FB.init({
              appId      : 'XXXXXXXXX',
              xfbml      : true,
              version    : 'v2.2'
            });

           // Additional initialization code such as adding Event Listeners goes here


         };

            (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/sdk.js";
                     fjs.parentNode.insertBefore(js, fjs);
                   }(document, 'script', 'facebook-jssdk'));

       </script>

   </body>
   </html>

【问题讨论】:

  • 我不明白为什么这不起作用。浏览器控制台中的任何错误?你能展示一个页面标签的实例吗?
  • 好的,你需要先去阅读Platform Policies——不允许让别人分享来参加比赛。
  • 谢谢 - 没有意识到这一点。现在好像很多人都这样做了,但我现在把它拿下来了。仍然没有回答为什么它不起作用的问题。

标签: javascript facebook


【解决方案1】:

它在台式机和安卓上运行良好,但在 iPhone 上却不行。以下功能在 iphone 中分享帖子但未显示帖子已发布(我认为响应在 iphone 5 中不起作用)。并更改所有参数

<script src="http://code.jquery.com/jquery.min.js"></script>
<script src="http://connect.facebook.net/en_US/all.js" type="text/javascript" charset="utf-8"></script>
<div id="fb-root"></div>    
<script type="text/javascript" charset="utf-8">
FB.init({
    appId: 'xxxxxxxxxxxxxx', 
    status: true, 
    cookie: true,
    xfbml: true
});

function share_prompt() {
FB.ui( {
method: 'feed',
name: "fsdfsdf",
link: "abc.com/share-it/",
picture: "FacbookShareRed.jpg"

}, function( response ) {

if (response && response.post_id) {
          alert('Post was published.');
         } else {
           alert('Post was not published.');
         }


} );
}
$(document).ready(function(){
$('button.share-btn').on( 'click', fb_share );
});

</script>
<a class="sc-facebook" value="Share with Facebook" onclick="share_prompt();">Share with Facebook</a>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-09-27
    • 1970-01-01
    • 1970-01-01
    • 2015-06-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多