Antwort #28 am: 18. Oktober 2012, 14:21:40
Ansatz:
FB Javascript SDK benutzen, um Login durchzuführen.
Das FB PHP-SDK benutzen, um Informationen der Nutzer auszulesen und neue Nutzer anzulegen.
in der general.js.php:
Sinnvoll in einem script Block einfügen:
/*
* FB Javascript Login Popup & redirect
*/
<?php
$page = "http://";
$page .= $_SERVER['SERVER_NAME'];
if($_SERVER['SERVER_PORT'] == '8888') {
$page .= ":".$_SERVER['SERVER_PORT'];
}
?>
function thFBShortCut() {
//alert('shortcut');
FB.login(function(response) {
if (response.authResponse) {
window.location = '<?php echo $page;?>/fb_login.php?action=fb_login';
}
/*,publish_stream,publish_actions,offline_access, user_status*/
}, {scope: 'email,user_about_me,user_hometown,user_interests,user_likes,user_website,user_birthday'});
}
Füge an gewünschte Loginlinks ein "onclick='thFBShortCut(); return false'" an. Setze Link auf gewünschtes Loginscript
in der includes/header.php am Ende - benutzt ihr facebook plugins schon, ggf. mehrfach auftauchende Sachen nicht wiederholen:
?>
<div id="fb-root"></div>
<?php
$fb = new fb_api();
?>
<script type="text/javascript">
window.fbAsyncInit = function() {
FB.init({
appId : '<?php echo $fb->appid; ?>', // App ID
/*channelUrl : '', // 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>
Eine Instanz meiner FB-Klasse wird erstellt und die app ID daraus herausgelesen