How to check if the user’s shared website (Facebook) was? Is it possible?

I am currently writing a website and I need help integrating facebook. I need a function (PHP or JS, both help) that can check if this user provided my site, and I could not find out how to write it. Could you point me in the right direction?

+6
source share
2 answers

First you need to download the Facebook SDK right after your tag:

<div id="fb-root"></div> <script> window.fbAsyncInit = function() { FB.init({ appId : "YOUR APP ID", status : true, // check login status cookie : true, // enable cookies to allow the server to access the session xfbml : false, // parse XFBML perms : 'read_stream', access_token : "USER ACCESS TOkEN", frictionlessRequests : true }); }; // Load the SDK Asynchronously (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/pt_BR/all.js"; fjs.parentNode.insertBefore(js, fjs); }(document, 'script', 'facebook-jssdk')); </script> 

Then you can use the callback function to accomplish what you want:

 <script type="text/javascript"> function shareOnFacebook() { FB.ui( { method : 'feed', display : 'iframe', name : 'name', link : 'http://www.linktoshare.com', picture : 'http://www.linktoshare.com/images/imagethumbnail.png', caption : 'txt caption', description : 'txt description', access_token : 'user access token' }, function(response) { if (response && response.post_id) { // HERE YOU CAN DO WHAT YOU NEED alert('OK! User has published on Facebook.'); } else { //alert('Post was not published.'); } } ); } </script> 

Then you should use it as follows:

 <a href="#" onclick="shareOnFacebook();">Share on facebook</a> 
+7
source

Using the JavaScript SDK, FB.ui() and feed , you can offer your users to share the URL on Facebook. This dialog box presents the callback function so that you can determine if the post was successfully delivered.
Sample code taken from the specified 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. However, this will not allow you to test if someone shared the URL of your site outside of your feed dialog.


A more sophisticated alternative that does not require a dialog callback can be accomplished using read_stream permission. After you get this permission, you can scan users for previous messages to see if he shared your site on his wall ...

Keep in mind that this will not work if a user shares your site on some other wall or page ...

+5
source

Source: https://habr.com/ru/post/918660/


All Articles