简体   繁体   中英

How to pass facebook login response from javascript to php page?

I am trying to add loing with facebook feature to my website, I used javascript to connect to facebook API, As you know facebook sends object named "response", I want to pass this object to my index.php page to read its content their.

could you please tell me how to pass and read this opject

If you need to work with facebook from your server, you can't use just js auth.

You need to implement "server login", described at Login for Server-side Apps

You need not implement all that complicated things, just find any library from internet, FB have its own library for php as I know, and use it to make server login. You can find many examples how to do it.

You can done with it by using jQuery.ajax() or jQuery.post() function. but it is not secured. Because js is open for all browser. Bad guys can send unexpected data and take chances to harm your app / web. Anyway it is your choice.

You can add a function here i have used replace_login() in FB.getLoginStatus() as following:

FB.getLoginStatus(function(response) {
        if (response.status === 'connected') {
            // connected
    replace_login();
        } else if (response.status === 'not_authorized') {
            // not_authorized
        } else {
            // not_logged_in
        }
    });

Now write replace_login() in same file and after FB.getLoginStatus() as below:

function replace_login(){
       FB.api('/me', function(response) {
          $.post("http://yourdomain.com/ajax_post_login",{ username: response.username, name: response.name, fb_res: response }, function(data) {
              alert(data);
          })
       });
  }

Check facebook server-side-login , it will help you more.

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