Advertisement
Guest User

Untitled

a guest
Apr 19th, 2014
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.69 KB | None | 0 0
  1. {scope: 'publish_stream'}
  2.  
  3. // Click Handler for the login.
  4. $(document).delegate('#fb-connect', 'click', function(e){
  5. e.preventDefault();
  6. FB.login(function(response) {
  7.  
  8. // Check the status
  9. // console.log(response.status);
  10.  
  11. if (response.status === 'connected') {
  12.  
  13. // Run the function we created below to publish to the users stream.
  14. publish('I just logged in via Facebook. '); // Your Message
  15.  
  16. } else if (response.status === 'unknown' || response.status === 'not_authorized') {
  17. // Something else if they chose not to connect
  18. } else {
  19.  
  20. }
  21.  
  22. }, {scope: 'publish_stream'});
  23.  
  24. });
  25.  
  26. function publish(messagebody) {
  27.  
  28. var body = messagebody; // This is the passed in string aka message you want to post.
  29.  
  30.  
  31. params = {
  32. message: body, // Your message body
  33. link: 'http://www.yoursite.com' // if you want to share a link.
  34. }
  35.  
  36. FB.api('/me/feed', 'post', params, function(response) {
  37. if (!response || response.error) {
  38. //alert('Error occured');
  39. console.log(response.error);
  40. } else {
  41. // Successful post to facebook.
  42. // alert('Post ID: ' + response.id);
  43.  
  44. }
  45. });
  46. }
  47.  
  48. <html>
  49. <head>
  50. <title>Your Page</title>
  51. <!-- Load the Facebook SDK for your APP -->
  52. <script>
  53. window.fbAsyncInit = function() {
  54. // init the FB JS SDK
  55. FB.init({
  56. appId : 'YOURAPPID', // Test App ID for localhost
  57. channelUrl : '//WWW.YOUR_DOMAIN.COM/channel.html', // Channel file for x-domain comms
  58. status : true, // Check Facebook Login status
  59. xfbml : true // Look for social plugins on the page
  60. });
  61.  
  62. // Additional initialization code such as adding Event Listeners goes here
  63. };
  64.  
  65. // Load the SDK asynchronously
  66. (function(d, s, id){
  67. var js, fjs = d.getElementsByTagName(s)[0];
  68. if (d.getElementById(id)) {return;}
  69. js = d.createElement(s); js.id = id;
  70. js.src = "//connect.facebook.net/en_US/all.js";
  71. fjs.parentNode.insertBefore(js, fjs);
  72. }(document, 'script', 'facebook-jssdk'));
  73. </script>
  74. </head>
  75. <body>
  76.  
  77.  
  78. <!-- Markup for Connect Button -->
  79. <a id="fb-connect">
  80. <img src="URLTOANIMAGEYOULIKEFORTHEBUTTON">
  81. </a>
  82.  
  83. <!-- Reference to Jquery -->
  84. <script src="PATHTOJQUERY"></script>
  85.  
  86. <!-- Some Additional Script to handle the functions / Could also be another JS file you include. -->
  87. <script>
  88. $(document).ready(function(){
  89.  
  90. // Bind the Click of the Button fb-connect
  91. $(document).delegate('#fb-connect', 'click', function(e){
  92. e.preventDefault();
  93. FB.login(function(response) {
  94.  
  95. // Check the status
  96. // console.log(response.status);
  97.  
  98. if (response.status === 'connected') {
  99.  
  100. // Run the function we created below to publish to the users stream.
  101. publish('I just logged in via Facebook. '); // Your Message
  102.  
  103. } else if (response.status === 'unknown' || response.status === 'not_authorized') {
  104. // Something else if they chose not to connect
  105. } else {
  106.  
  107. }
  108.  
  109. }, {scope: 'publish_stream'});
  110.  
  111. });
  112. });
  113.  
  114.  
  115. function publish(messagebody) {
  116.  
  117. var body = messagebody; // This is the passed in string aka message you want to post.
  118.  
  119.  
  120. params = {
  121. message: body, // Your message body
  122. link: 'http://www.yoursite.com' // if you want to share a link.
  123. }
  124.  
  125. FB.api('/me/feed', 'post', params, function(response) {
  126. if (!response || response.error) {
  127. //alert('Error occured');
  128. console.log(response.error);
  129. } else {
  130. // Successful post to facebook.
  131. // alert('Post ID: ' + response.id);
  132.  
  133. }
  134. });
  135. }
  136.  
  137. </script>
  138.  
  139. </body>
  140. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement