简体   繁体   English

如何将javascript的facebook登录响应传递给php页面?

[英]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. 我正在尝试将loing与facebook功能添加到我的网站,我使用javascript连接到facebook API,如你所知facebook发送对象名为“response”,我想将此对象传递给我的index.php页面来阅读其内容他们的。

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. 如果您需要从服务器使用Facebook,则不能仅使用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. 你不需要实现所有复杂的东西,只需从互联网上找到任何库,FB就像我所知拥有自己的php库,并使用它来进行服务器登录。 You can find many examples how to do it. 你可以找到很多如何做的例子。

You can done with it by using jQuery.ajax() or jQuery.post() function. 您可以使用jQuery.ajax()jQuery.post()函数来完成它。 but it is not secured. 但它没有安全保障。 Because js is open for all browser. 因为js对所有浏览器都是开放的。 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()使用了replace_login() ,如下所示:

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: 现在在同一个文件中写入replace_login()并在FB.getLoginStatus()之后FB.getLoginStatus()如下:

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. 检查facebook服务器端登录 ,它会对你有所帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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