flexible feed dialog function for Facebook JavaScript SDK FB.ui


/ Published in: JavaScript
Save to your folder(s)

A more flexible version of the 'official' Facebook feed dialog example.

"The Feed Dialog prompts the user to publish an individual story to a profile's feed. This does not require any extended permissions."

"The following simple JavaScript example demonstrates using the FB.ui method in the JavaScript SDK to use the Feed Dialog:"


Copy this code and paste it in your HTML
  1. <html xmlns="http://www.w3.org/1999/xhtml" xmlns:fb="http://www.facebook.com/2008/fbml">
  2. <head>
  3. </head>
  4. <body>
  5.  
  6. <div id="fb-root"></div>
  7.  
  8. <script>
  9. window.fbAsyncInit = function() {
  10. FB.init({
  11. appId: "***********",
  12. channelURL : '//http://www.dr.dk/', // Channel File
  13. status: true,
  14. cookie: true,
  15. oauth : true, // enable OAuth 2.0
  16. xfbml: true
  17. });
  18. };
  19.  
  20. (function() {
  21. var e = document.createElement('script');
  22. e.async = true;
  23. e.src = document.location.protocol + '//connect.facebook.net/da_DK/all.js';
  24. document.getElementById('fb-root').appendChild(e);
  25. }());
  26.  
  27. function streampublish(obj) {
  28. // params: title, targethref, imgsrc, caption, description, message
  29.  
  30. // set default or passed parameters
  31. obj.title = (obj.title === undefined) ? "" : obj.title;
  32. obj.targethref = (obj.targethref === undefined) ? "" : obj.targethref;
  33. obj.imgsrc = (obj.imgsrc === undefined) ? "" : obj.imgsrc;
  34. obj.caption = (obj.caption === undefined) ? "" : obj.caption;
  35. obj.description = (obj.description === undefined) ? "" : obj.description;
  36. obj.message = (obj.message === undefined) ? "" : obj.message;
  37.  
  38. FB.ui(
  39. {
  40. method: 'feed',
  41. name: obj.title,
  42. link: obj.targethref,
  43. picture: obj.imgsrc,
  44. caption: obj.caption,
  45. description: obj.description,
  46. message: obj.message
  47. }/*,
  48. function(response) {
  49. if (response && response.post_id) {
  50. alert('Post was published.');
  51. } else {
  52. alert('Post was not published.');
  53. }
  54. }*/
  55. );
  56. }
  57.  
  58. </script>
  59. </body>
  60. </html>

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.