对于 JS 解决方案,您可以在 fan.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
oauth : true, // enable OAuth 2.0
xfbml : true // parse XFBML
});
// Additional initialization code here
};
// Load the SDK Asynchronously
(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>
<button id="fb-login">Login & Permissions</button>
<script>
document.getElementById('fb-login').onclick = function() {
var cb = function(response) {
if (response.status === 'connected') {
//user is logged in here and you have email scope already
} else {
alert('Click the "Login and Permissions" button so we can send you emails');
}
};
FB.login(cb, { scope: 'email' });
};
</script>
channel.html 的内容应该只是
<script src="//connect.facebook.net/en_US/all.js"></script>
我没有时间对此进行测试,我从官方文档中提取了大部分内容。我知道你说你不想要链接。但是您可能会发现此页面很有用
https://developers.facebook.com/docs/reference/javascript/
还有一个测试控制台,您可以在其中使用位于此处的 javascript api
https://developers.facebook.com/tools/console/