用FB按钮登录
问题描述:
我正在使用CS购物车电子商务系统,并且我已经浏览了Facebook和其他各种网站上的所有教程,以便将facebook集成到我的网站。意思是,我在我的网站上有标准的用户注册。然而,我正在寻找实现登录Facebook的按钮,其中一个Facebook用户将能够登录使用他的Facebook的凭据。我也被要求参考https://github.com/facebook/facebook-php-sdk用FB按钮登录
我不是一个程序员来理解这一点。如果有人能帮上忙,那会很好。
在此先感谢。
答
为您需要创建app in the facebook比你需要的AppKey和分泌
,并设置URL确保该网站的网址是,你必须在同一页上登录按钮并且不能在同一个应用程序的多个地方登录按钮
和下面的脚本
<?php
define('YOUR_APP_ID', 'YOUR APP ID');
//uses the PHP SDK. Download from https://github.com/facebook/php-sdk
require 'facebook.php';
$facebook = new Facebook(array(
'appId' => YOUR_APP_ID,
'secret' => 'YOUR APP SECRET',
));
$userId = $facebook->getUser();
?>
<html>
<body>
<div id="fb-root"></div>
<?php if ($userId) {
$userInfo = $facebook->api('/' . $userId); ?>
Welcome <?= $userInfo['name'] ?>
<?php } else { ?>
<fb:login-button></fb:login-button>
<?php } ?>
<div id="fb-root"></div>
<script>
window.fbAsyncInit = function() {
FB.init({
appId : 'YOUR_APP_ID', // App ID
channelUrl : '//WWW.YOUR_DOMAIN.COM/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
});
FB.Event.subscribe('auth.login', function(response) {
window.location.reload();
});
};
// 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>
</body>
</html>
看到完整的文档和教程