How to check if user shared website (Facebook)? Is it possible?

前端 未结 2 1263
醉梦人生
醉梦人生 2021-02-15 23:45

I am currently writing a website and I need some help about facebook integration. I need a function (PHP or JS, both will help) that can check if a given user shared my website,

2条回答
  •  温柔的废话
    2021-02-15 23:56

    Using the JavaScript SDK, FB.ui() and the feed dialog, you can prompt your users to share a URL on Facebook. This dialog provides a callback function so that you can tell if the post was made successfully.
    Code sample lifted from the above link...

     var obj = {
        method: 'feed',
        link: 'https://developers.facebook.com/docs/reference/dialogs/',
        picture: 'http://fbrell.com/f8.jpg',
        name: 'Facebook Dialogs',
        caption: 'Reference Documentation',
        description: 'Using Dialogs to interact with users.'
    };
    
    function callback(response) {
        document.getElementById('msg').innerHTML = "Post ID: " + response['post_id'];
    }
    
    FB.ui(obj, callback);
    

    This is the easiest way to accomplish what you need. It will not, however, allow you to test if someone shared your website's URL outside of your feed dialog.


    A more complex alternative not requiring the dialog callback could be accomplished by utilizing the read_stream permission. Once you have that permission, you can scan the users past posts to see if he has ever shared your website on his wall...

    Keep in mind that this will not work if the user shared your website on some one else's wall or on a page...

提交回复
热议问题