javascript - Facebook Share callback not working -
i'm trying setup facebook page-tab app contains share button. works fine enough present share dialog, callback isn't being called. if put fb.ui function inside window.fbasyncinit function, callback works great. but, doing makes share window appear on page load. i'd have show on button click. i've tried calling window.fbasyncinit function after button clicked, doesn't work either. here's full html of page:
<html> <head> </head> <body style="background-color:#9ec64e;"> <div id="fb-root"></div> <table style="width:100%"> <tr><td> <br> <h1>press button share</h1> </td> <td> <p id="enterbutton"><a href='' onclick="showshare();"><img src='share_btn.png' style='width:200px;'></a></p> </td> </tr> </table> <script> function showshare() { console.log("showshare"); fb.ui( { method: 'feed', name: 'facebook dialogs', // name of product or content want share link: 'https://developers.facebook.com/docs/reference/dialogs/', // link product or content sharing picture: 'http://fbrell.com/f8.jpg', // path image share content caption: 'reference documentation', // caption description: 'dialogs provide simple, consistent interface applications interface users.' // description of product or content }, function(response) { console.log("finished"); if (response && response.post_id) { alert('post published.'); } else { alert('post not published.'); } } ); } window.fbasyncinit = function() { // init fb js sdk fb.init({ appid : 'xxxxxxxxx', xfbml : true, version : 'v2.2' }); // additional initialization code such adding event listeners goes here }; (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/en_us/sdk.js"; fjs.parentnode.insertbefore(js, fjs); }(document, 'script', 'facebook-jssdk')); </script> </body> </html>
it working fine in desktop , android not working in iphone. following function shares post in iphone not showing post published ( think response not working in iphone 5 ). , change parameters
<script src="http://code.jquery.com/jquery.min.js"></script> <script src="http://connect.facebook.net/en_us/all.js" type="text/javascript" charset="utf-8"></script> <div id="fb-root"></div> <script type="text/javascript" charset="utf-8"> fb.init({ appid: 'xxxxxxxxxxxxxx', status: true, cookie: true, xfbml: true }); function share_prompt() { fb.ui( { method: 'feed', name: "fsdfsdf", link: "abc.com/share-it/", picture: "facbooksharered.jpg" }, function( response ) { if (response && response.post_id) { alert('post published.'); } else { alert('post not published.'); } } ); } $(document).ready(function(){ $('button.share-btn').on( 'click', fb_share ); }); </script> <a class="sc-facebook" value="share facebook" onclick="share_prompt();">share facebook</a>
Comments
Post a Comment