Facebook - JavaScript SDK and saving user information in a database

I did some research and I found that the JavaScript JavaScript SDK on Facebook is better than the PHP SDK. Now I take user information using JavaScript, for example 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 the Internet but found nothing. Is there a way to store this information in a database?

+4
source share
1 answer

Javascript runs on the client side, while PHP runs on the server side. The Javascript SDK is usually used on the client side, only to enrich the user interface (for example, add a โ€œwelcome X!โ€ To the screen), and not to collect data and store the database.

However, if you want to save them to the database, you must send them from the client to your server using an AJAX request, for example:

$.post("/your/php/endpoint/here", rows) in jQuery.

But there is a security problem , the user can send information about the offline user, bypassing the Facebook API. So, to store data on the server, I recommend that you receive information on the server.

You can do this in two ways:

  • Get the access token using JS api and send the token to the server and collect information on the server by going to the api schedule.

  • User authorization on the server.

0
source

Source: https://habr.com/ru/post/1402139/


All Articles