简体   繁体   English

Facebook - JavaScript SDK并将用户信息保存到数据库

[英]Facebook - JavaScript SDK and saving user information to a database

I made some research and I found that the Facebook JavaScript SDK is better than the PHP SDK. 我做了一些研究,发现Facebook JavaScript SDK比PHP SDK更好。 Now I take the user information with JavaScript like with FQL : 现在我使用JavaScript获取用户信息,如FQL

function fqlQuery(){
    showLoader(true);

    FB.api('/me', function(response) {
        showLoader(false);

        //http://developers.facebook.com/docs/reference/fql/user/
        var query = FB.Data.query('select name, profile_url, sex, pic_small from user where uid={0}',
                                  response.id);
        query.wait(function(rows) {
            document.getElementById('debug').innerHTML =
                'FQL Information: '+  "<br />" +
                'Your name: '      +  rows[0].name                                                            + "<br />" +
                'Your Sex: '       +  (rows[0].sex!= undefined ? rows[0].sex : "")                            + "<br />" +
                'Your Profile: '   +  "<a href='" + rows[0].profile_url + "'>" + rows[0].profile_url + "</a>" + "<br />" +
                '<img src="'       +  rows[0].pic_small + '" alt="" />' + "<br />";
         });
    });
}

I searched on the Internet, but I did not find anything. 我在互联网上搜索,但我没有找到任何东西。 Is there a way to store this information to a database? 有没有办法将此信息存储到数据库?

Javascript runs on client side and PHP runs on server side. Javascript在客户端运行,PHP在服务器端运行。 Javascript SDK is generally used on client side, only to " enrich " UI, (such as adding "Welcome X!" to screen) not to fetch data and store an a DB. Javascript SDK通常在客户端使用,仅用于“ 丰富 ”UI (例如向屏幕添加“Welcome X!”)不获取数据和存储数据库。

However, If you do want to store them on a DB, you should send them from client to your server via an AJAX request, such as: 但是,如果您确实希望将它们存储在数据库中,则应通过AJAX请求将它们从客户端发送到服务器,例如:

$.post("/your/php/endpoint/here", rows) in Jquery. Jquery中的$.post("/your/php/endpoint/here", rows)

But there is a security problem here , user may send arbitary user info by bypassing Facebook's API. 但是这里存在安全问题 ,用户可以绕过Facebook的API发送任意用户信息。 So, to store data on a server I recommend you to fetch information on server. 因此,要在服务器上存储数据,我建议您在服务器上获取信息。

You can do this in two ways: 您可以通过两种方式执行此操作:

  1. Get access token with JS api and send token to server and gather info on server by going to graph api. 使用JS api获取访问令牌并将令牌发送到服务器并通过转到图形API来收集服务器上的信息。

  2. User server side authantication. 用户服务器端身份验证。

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

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