I want to use facebook javascript sdk to share a page on facebook, and when a user share successfully I want to be able to track that on the current page without refreshing current page.
Now I have this code bellow, that opens the dialog successfully and share as well, but the popup doesn't close when I share or cancel. it only close when I use the cross in the top right corner.
Second problem is, I don't get notified when the user share successfully.
Note : if I use the code that fires the share dialog in $document.ready() instead of the click event on the open link, then it closes correctly, and call the attached functions as well where I console.log(response); but it has the same results for both successful share or cancel.
If I use feed dialog instead, the problem with closing the dialog stays, however the notifications is fine, I get notified back with the post_id, and that is perfect but I want to use share dialog not feed.
Bellow is all the code, sorry I couldn't make a jsfiddle, I tried but couldn't get facebook app work there.
<a href="" class="share">Open</a>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script>
<div id="fb-root"></div>
<script>
$(document).ready(function() {
$.ajaxSetup({ cache: true });
$.getScript('//connect.facebook.net/en_US/sdk.js', function(){
FB.init({
appId: '905779996145989',
version: 'v2.3'
});
});
$('.share').click(function() {
/*FB.ui({
method: 'feed',
link: 'http://ift.tt/1nt9Vwm',
caption: 'An example caption'
}, function(response){
console.log(response);
});*/
FB.ui({
method: 'share',
href: 'http://ift.tt/1nt9Vwm',
}, function(response){
console.log(response);
});
})
});
</script>
Aucun commentaire:
Enregistrer un commentaire