PHP Facebook Connect教程

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了PHP Facebook Connect教程相关的知识,希望对你有一定的参考价值。

<?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
define('YOUR_APP_ID', '32WEWWEWWEWEWEWEWEW24');
define('YOUR_APP_SECRET', '49fd00ce6237WEEWEWEWEWEW2');
 
//
// new facebook object to interact with facebook
$facebook = new Facebook(array(
 '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);
 
echo "<p>YOU ARE: <strong>". $userInfo['name'] ."</strong><br/>";
 echo "Your birth date is: ".$userInfo['birthday']."</p>";
 
 
 
} 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>

以上是关于PHP Facebook Connect教程的主要内容,如果未能解决你的问题,请参考以下文章

Facebook Connect - 同时使用 FBML 和 PHP 客户端

Facebook-connect:无法使用PHP SDK + JS SDK注销

spring security 与 facebook connect 集成

PHP PHP和MySQL Facebook连接教程

PHP和MySQL Facebook连接教程

Facebook 登录:如何将 JavaScript 与 PHP SDK 结合起来?