Facebook API:如何获取特定用户的URL份额?

时间:2014-10-02 21:47:04

标签: php facebook-graph-api cakephp oauth facebook-sharer

我正在构建一个网络广告系列应用,用户oauths可以选择20个不同的可共享图像。我需要跟踪用户共享总次数以及可能共享的次数。

第二个更简单的选项是在点击页面上的分享按钮时跟踪计数。虽然这不会给出准确的计数,因为用户可以单击站点上的共享按钮,等待.sharer窗口弹出,关闭它并最终游戏该站点。我想避免这种情况。

还有其他方法可以跟踪用户分享的内容吗?

我在Cakephp中构建它。

1 个答案:

答案 0 :(得分:1)

如果您使用JavaScript SDK,则可以跟踪用户共享的内容,并且只有在成功共享时才能跟踪。实现此目的的基本代码。您可以为每个图像发送唯一标识符,以便了解共享的图像。当然,这仍然可以由用户进行游戏 - 他们可以共享图像,然后将其从时间线中删除。

function fb_share() {
    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' ) {
          // ajax call to track share
        }
    } );

}

You can find the complete code and working example here