简体   繁体   中英

Facebook SDK Javascript and PHP

So I'm creating an application within a the CodeIgniter framework that works as a points system with Facebook. It basically will give you points for sharing, liking etc. I'm using the PHP SDK for authentication and it works great but unfortunately the iframe method of liking and sharing won't work because I need to attach a Callback.

So I know there is the Javascript SDK which has the Like Button feature but can a callback be attached? And if so, can the Javascript and PHP SDK work together so you wouldn't need to authenticate twice? Or is there a way to accomplish all of this strictly with the PHP SDK? I really need to be able to like and attach a callback to it. Thanks!

edit: Attached Javascript SDK code

<script>
  window.fbAsyncInit = function() {
    FB.init({
      appId      : '346032368781548', // App ID
      channelUrl : '//localhost/channel.html', // Channel File
      status     : true, // check login status
      cookie     : true, // enable cookies to allow the server to access the session
      xfbml      : true  // parse XFBML
    });

    // Additional initialization code here
  };

  // Load the SDK Asynchronously
  (function(d){
     var js, id = 'facebook-jssdk', ref = d.getElementsByTagName('script')[0];
     if (d.getElementById(id)) {return;}
     js = d.createElement('script'); js.id = id; js.async = true;
     js.src = "//connect.facebook.net/en_US/all.js";
     ref.parentNode.insertBefore(js, ref);
   }(document));
</script>

<fb:like send="true" width="450" show_faces="true" />
<script type="text/javascript">
    FB.Event.subscribe('edge.create',
        function(response) {
            alert('You liked the URL: ' + response);
            // Replace with the function that you want
        }
    );
</script>

Yes, you can run a callback via a second parameter, and if you use Facebook JavaScript SDK with PHP SDK, you shouldn't have any issues as long as the user is logged in and/or authorized. You have to, however add the Facebook Like button, and add this function like such:

<script type="text/javascript">
    FB.Event.subscribe('edge.create',
        function(response) {
            alert('You liked the URL: ' + response);
            // Replace with the function that you want
        }
    );
</script>

If you use Facebook Ignited it will allow you to easily integrate the Facebook PHP SDK with CodeIgniter. It also extends the functionality giving you easy to use functions.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM