/ Published in: PHP
URL: http://www.barattalo.it/facebook-connect-tutorial-new-version/
I will show you how to crate an app for facebook to handle the facebook connect process on your web site. Then I will show you the php code to perform the login on facebook and retrieve the informations you need for your site. The last suggestion will point how to merge facebook users with your users. Follow the link above to get the full tutoriall with text and images.
Expand |
Embed | Plain Text
<?php // // uses the PHP SDK. Download from https://github.com/facebook/php-sdk include("facebook-php-sdk/src/facebook.php"); // // from the facebook app page // // new facebook object to interact with facebook 'appId' => YOUR_APP_ID, 'secret' => YOUR_APP_SECRET, )); // // if user is logged in on facebook and already gave permissions // to your app, get his data: $userId = $facebook->getUser(); ?> <html> <head> <style>body { text-align:center; font-size: 40px }</style> </head> <body> <?php if ($userId) { // // already logged? show some data $userInfo = $facebook->api('/' + $userId); } else { // // use javaascript api to open dialogue and perform // the facebook connect process by inserting the fb:login-button ?> <div id="fb-root"></div> <fb:login-button scope='email,user_birthday'></fb:login-button> <?php } ?> <script> window.fbAsyncInit = function() { FB.init({ appId : <?=YOUR_APP_ID?>, status : true, cookie : true, xfbml : true, oauth : true, }); FB.Event.subscribe('auth.login', function(response) { // ------------------------------------------------------ // This is the callback if everything is ok window.location.reload(); }); }; (function(d){ var js, id = 'facebook-jssdk'; if (d.getElementById(id)) {return;} js = d.createElement('script'); js.id = id; js.async = true; js.src = "//connect.facebook.net/en_US/all.js"; d.getElementsByTagName('head')[0].appendChild(js); }(document)); </script> </body> </html>
Comments
Subscribe to comments
You need to login to post a comment.

Useful Facebook connect tutorial to create app for Facebook. It's a great app to handle Facebook connect process from your website and able to retrieve users information for your websites. Finally, great tutorial to apply in everyone websites.