简体   繁体   中英

How do I store the ID and email into a database?

I keep trolling the internet for tutorials on how to do this to no avail. I followed this on getting it set up, but it doesn't go through how to save the information received. Actually it doesn't go through if there is and information received.

Thanks so much!!

more information. What I want to do is have a FB login to my site. If it is a fist time user, I want his ID, name, and email saved to a database. If it's an old user, then I need his ID to check it against the database.

heres my current code:

 <html>
<head>
  <title>My Facebook Login Page</title>
</head>
<body>
  <div id="fb-root"></div>
  <script>
    window.fbAsyncInit = function() {
      FB.init({
        appId      : '223157403572264',
        status     : true, 
        cookie     : true,
        xfbml      : true,
        oauth      : true,
      });
    };
    (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>
  <div class="fb-login-button" data-scope="email,user_checkins">
    Login with Facebook
  </div>
</body>

edit- more information

edit2- my code

Just after the init of your Facebook object, you can "subscribe" to events, like saying "when my user is just logged in, i want to do that..." For further informations about that, you can look to this topic !

But what you really need is, i think, to use the FB.api to call for specific informations about the user. Once he's logged in you can call this function like this :

FB.api('/me', function(response) {
  alert(response.name);
});

You make a call to retrieve information about /me (= the current logged in user), then you have your callback function which you can use to send your data with an AJAX call or anything else to some server script that will store it to your Database, but you know how to do this part I think :)

For more informations sabout the FB.api your should check this documentation

If you receive the users data via javascript you could send a request to your own scripts via jQuery's post function. http://api.jquery.com/jQuery.post/ If you dont use jQuery the idea would be the same. Just us JS to send a POST Request to your own site/script and save that data in your database. See this for example: http://javascript.about.com/library/blajax01.htm - http://javascript.about.com/library/blajax02.htm

Or is your question like "how to store data in your own Database?"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM