|
public function authenticate_with_facebook() { |
|
?> |
|
<p><a href="#" onClick="logInWithFacebook()">Log In with the JavaScript SDK</a></p> |
|
<script> |
|
logInWithFacebook = function() { |
|
FB.login(function(response) { |
|
if (response.authResponse) { |
|
//alert('You are logged in & cookie set!'); |
|
// Now you can redirect the user or do an AJAX request to |
|
// a PHP script that grabs the signed request from the cookie. |
|
jQuery.ajax({ |
|
url: '<?php echo plugin_dir_url(__FILE__); ?>facebook-js-login.php', |
|
type: 'POST', |
|
data: { |
|
app_id: "<?php echo get_option('facebook_app_id'); ?>", |
|
app_secret: "<?php echo get_option('facebook_app_secret'); ?>" |
|
} |
|
}).done(function(data){ |
|
//alert(JSON.stringify(data)); |
|
}); |
|
|
|
} else { |
|
//alert('User cancelled login or did not fully authorize.'); |
|
} |
|
}, {scope: 'public_profile, email, user_likes, user_photos, user_posts, user_events'}); |
|
return false; |
|
}; |
|
window.fbAsyncInit = function() { |
|
FB.init({ |
|
appId: <?php echo get_option('facebook_app_id'); ?>, |
|
cookie: true, // This is important, it's not enabled by default |
|
version: 'v2.2' |
|
}); |
|
}; |
|
|
|
(function(d, s, id){ |
|
var js, fjs = d.getElementsByTagName(s)[0]; |
|
if (d.getElementById(id)) {return;} |
|
js = d.createElement(s); js.id = id; |
|
js.src = "//connect.facebook.net/en_US/sdk.js"; |
|
fjs.parentNode.insertBefore(js, fjs); |
|
}(document, 'script', 'facebook-jssdk')); |
|
</script> |
|
<?php |
|
} |