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, and I couldn’t find out how to write one. Could you please point me at the right direction?
Upload an HTML file provided by Facebook to your web directory and confirm domain ownership in Business Manager. Add a meta tag to the <head> section of your domain home page If you are verifying a domain on behalf of a client (e.g. as an agency) please make sure that the domain is verified in the domain owner's Business Manager.
You can find more information about implementing the fb:pages tag in the Open Graph - Object Properties documentation.
Download the HTML verification file. Upload the file to the root directory of your website. You will be able to see that it is uploading at the link provided in the HTML File Upload tab. Once it is done, click the Verify button at the bottom of the HTML File Verification tab for the selected domain.
First you have to load 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 do 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 like this:
<a href="#" onclick="shareOnFacebook();">Share on facebook</a>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With