如何检查用户是否在墙上共享信息?

时间:2014-05-12 14:30:09

标签: facebook-php-sdk

我需要做的是当用户登录游戏并分享我们的推荐图片时,我希望检查是否共享成功并添加额外的XP积分。所以我创建了这样的链接:

<a onClick="window.open('http://www.facebook.com/sharer.php?s=100&amp;p[title]=Title of sharer;&amp;p[summary]=Descriobe abiut game etc&amp;p[url]=http://google.com&amp;&amp;p[images][0]=http://www.some.jpg','sharer','toolbar=0,status=0,width=548,height=455');" href="javascript: void;">
test </a>

所以我没有回复实施。我是否需要在fb中创建一些APP并使用我的APP ID进行API或如何解决此问题?

1 个答案:

答案 0 :(得分:-1)

您可以使用Facebook JavaScript SDK跟踪用户是否成功分享了某些内容。 This tutorial展示了如何实现这一目标。

如果您使用FB.ui对话框与墙壁共享内容,则可以向该功能添加回调以跟踪成功/失败,如下所示:

FB.ui( {
    method: 'feed',
    name: "Facebook API: Tracking Shares using the JavaScript SDK",
    link: "https://www.webniraj.com/2013/05/11/facebook-api-tracking-shares-using-the-javascript-sdk/",
    picture: "https://stackexchange.com/users/flair/557969.png",
    caption: "Tracking Facebook Shares on your website or application is a useful way of seeing how popular your articles are with your readers. In order to tracking Shares, you must used the Facebook JavaScript SDK."
}, function( response ) {
    if ( response !== null && typeof response.post_id !== 'undefined' ) {
        console.log( response );
        // ajax call to save response
      $.post( '{url_that_will_track_share}', { 'meta': response }, function( result ) {
        console.log( result );
      }, 'json' );
    }
} );

在此示例中,回调会使用Feed对话框中的响应触发对另一个页面的ajax调用。如果用户共享帖子,则响应将包含post_id。您可以使用ajax脚本检查post_id是否存在且是否有效,然后相应地奖励XP点。