【问题标题】:How to get response from facebook share button?如何从 Facebook 分享按钮获得响应?
【发布时间】:2016-05-12 16:39:07
【问题描述】:

这是来自 facebook 的 facebook 分享按钮代码

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

<!-- Your share button code -->
<div class="fb-share-button" 
    data-href="http://www.your-domain.com/your-page.html" 
    data-layout="button_count">
</div>

我怎样才能得到成功或错误的响应?

我尝试了一些示例,但通过代码分享后没有得到响应。

分享按钮有效,它也分享帖子。

   window.fbAsyncInit = function() {
            // init the FB JS SDK
            FB.init({
              appId      : '1743496239724', // App ID from the App Dashboard
              //channelUrl : 'http://exampb.com/plugins/', // Channel File for x-domain communication
              status     : true, // check the login status upon init?
              cookie     : true, // set sessions cookies to allow your server to access the session?
              xfbml      : true  // parse XFBML tags on this page?
            });

            // Additional initialization code such as adding Event Listeners goes here
            FB.ui(
              {
                method: 'feed',
              },
              function(response) {
                if (response && response.post_id) {
                  alert('Post was published.');
                } else {
                  alert('Post was not published.');
                }
              }
            );

          };

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

我试过这个,但它有冲突。使用从 FB 获得的分享按钮。

【问题讨论】:

    标签: javascript html facebook api


    【解决方案1】:

    您可以使用共享对话框,但只有当您使用publish_actions 权限授权用户时,它才会以适当的回调进行响应:https://developers.facebook.com/docs/sharing/reference/share-dialog

    【讨论】:

    • 我没找到路。我也为此签名并获得了应用 ID。
    • 未经授权,没有可靠的方法来获取回调。无论如何,你需要它做什么?分享后不要移除分享按钮,可能用户想再次分享。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-10-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-05-05
    • 2014-07-01
    相关资源
    最近更新 更多