Getting all your Facebook data is very easy with Facebook Login and native php
Facebook Login It is a very interesting tool that allows to speed up the login in websites and applications. Thus, when we enter with our Facebook user, the application or website takes the data we have associated with the profile, such as: name, surname, age range, sex and email.
The above turns out to be more agile and comfortable for the user as beneficial for the system administrator.
Next, I present to you how the relatively basic project to learn how to develop software with the php programming language is developed.
Project structure
config.php
<?php
session_start();
include_once("facebook-sdk-5/src/Facebook/autoload.php");
$fb = new Facebook\Facebook(array(
"app_id" => "*******", // Replace with your app id
"app_secret" => "*******************", // Replace with your app secret
"default_graph_version" => "v3.2",
));
$helper = $fb->getRedirectLoginHelper();
?>
Version 5 of the Facebook SDK is used, which is in charge of capturing the app id variables and the secret key that Facebook provides.
So what we are going to do here is assign the keys to the Facebook library, so that it can connect us well.
This file allows us to receive the response that Facebook returns in order to obtain the requested data, such as the profile photo and the username. This is how you can make the call of each of the variables that you want to obtain or bring to the application.
Once you have brought the data you decided to obtain, you can save it in your database if you wish.
logout.php
<?php
include_once("config.php");
session_destroy();
unset($_SESSION["fbUserId"]);
unset($_SESSION["fbUserName"]);
unset($_SESSION["fbAccessToken"]);
header("location: http://localhost/php-login-facebook/index.php"); /*change url for you localhost*/
exit;
?>
Logout is where the user's safe exit from the application is controlled by deleting their id and username.