[FACEBOOK] GET USER PERMISSION AND SAVA DATA VIA AJAX
What this code does:
1) after click, check if user is logged in FB
2) if it doesn't ask to log in
3) after login, it ask permission
4) if user accept it send gathered data to pass_value.php via Ajax and it will redirect the user to an other page called gosomewhere.php
// always put this function inside a click or a user action, don't automatically open it or browser will block the popup.
$('#button_id').click(function(){
FB.login(function(logged) {
if(logged.status == "connected"){
FB.api("/me", function(response) {
$.ajax({
type: "POST",
url: "pass_value.php",
data: {fb_id: response.id, name: response.first_name, last_name: response.last_name, gender: response.gender},
success: function(){window.location.href = "gosomewhere.php"; }
});
});
}
/* in the scope u specify all permission you need, in this case you get all basic INFO and pubblish to wall permission */
}, {scope: 'publish_stream'});
});
Written by Stefano Cerelli
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Javascript
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#