1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62
|
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script>
var Email;
window.fbAsyncInit = function() {
FB.init({
appId : '531377833592457', // App ID
channelUrl : 'http://credit-agricole-aquitaine.fr/clubetudiant/actus.php', // Channel File
status : true, // check login status
cookie : true, // enable cookies to allow the server to access the session
xfbml : true // parse XFBML
});
// Here we subscribe to the auth.authResponseChange JavaScript event. This event is fired
// for any authentication related change, such as login, logout or session refresh. This means that
// whenever someone who was previously logged out tries to log in again, the correct case below
// will be handled.
FB.Event.subscribe('auth.authResponseChange', function(response) {
// Here we specify what we do with the response anytime this event occurs.
if (response.status === 'connected')
{
console.log('connected');
testAPI();
}
else if (response.status === 'not_authorized')
{
console.log('not authorized');
FB.login();
}
else
{
FB.login();
}
});
};
// 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));
// Here we run a very simple test of the Graph API after login is successful.
// This testAPI() function is only called in those cases.
function testAPI() {
console.log('Welcome! Fetching your information.... ');
FB.api('/me', function(response) {
Email = response.email;
console.log('id, ' + response.id + '.');
console.log('mail, ' + response.email + '.');
console.log('name, ' + response.name + '.');
// @@@@@@ FONCTIONNE, MAIS JE RECUPERE LES DONNEES EN JAVASCRIPT. COMMENT RECUPERER L'EMAIL ET FAIRE UN SELECT EN BASE DE DONNEES ?
});
}
</script> |
Partager