I am trying to connect my Linkedin Login page to the database for getting user information. But whatever I did is just authorized to login a user and database is not receiving any information. Here is my index.php
<?php
require_once "init.php";
require_once "includes/db.php";
if(isset($_GET['code'])) // get code after authorization
{
$url = 'https://www.linkedin.com/uas/oauth2/accessToken';
$param = 'grant_type=authorization_code&code='.$_GET['code'].'&redirect_uri='.$config['callback_url'].'&client_id='.$config['Client_ID'].'&client_secret='.$config['Client_Secret'];
$return = (json_decode(post_curl($url,$param),true)); // Request for access token
if($return['error']) // if invalid output error
{
$content = 'Some error occured<br><br>'.$return['error_description'].'<br><br>Please Try again.';
}
else // token received successfully
{
$url = 'https://api.linkedin.com/v1/people/~:(id,firstName,lastName,pictureUrls::(original),headline,publicProfileUrl,location,industry,positions,email-address)?format=json&oauth2_access_token='.$return['access_token'];
$User = json_decode(post_curl($url)); // Request user information on received token
// Insert Data in Database
$query = "INSERT INTO `linkedti_scheduler`.`users`
(`userid`,
`firstName`,
`lastName`,
`emailAddress`,
`position`,
`location`,
`profileURL`,
`pictureUrls`,
`headline`)
VALUES
('$id',
'$firstName',
'$lastName',
'$emailAddress',
'$position',
'$location',
'$profileURL',
'$pictureUrls',
'$headline')";
mysqli_query($connection,$query);
}
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>****</title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.6/css/bootstrap.min.css" integrity="sha384-rwoIResjU2yc3z8GV/NPeZWAv56rSmLldC3R/AZzGRnGxQQKnKkoFVhFQhNUwEyJ" crossorigin="anonymous">
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.6/js/bootstrap.min.js" integrity="sha384-vBWWzlZJ8ea9aCX4pEW3rVHjgjt7zpkNpZk+02D9phzyeVkE+jo0ieGizqPLForn" crossorigin="anonymous"></script>
<link rel="stylesheet" href="css/style.css" />
</head>
<body class="bg">
<div align="center" class="logo">
<img src="images/logo.png" alt="logo" align="middle"/>
</div>
<div class="container">
<div class="row">
<div class="col-md-6 offset-md-3" id="button">
<a href="<?php echo "https://www.linkedin.com/oauth/v2/authorization?response_type=code&client_id=". CLIENTID . "&redirect_uri=".REDIRECTURI."&state=". CSRF."&scope=".SCOPES ; ?>" class="btn btn-md btn-outline-primary btn-block" style="border-radius: 0px;">Login with LinkedIn</a>
</div>
</div>
</div>
</body>
</html>
Here is my db.php
<?php
define('DB_SERVER', 'localhost'); // Database server
define('DB_USERNAME', '******'); // Database Username
define('DB_PASSWORD', '******'); // Database Password
define('DB_DATABASE', '*******'); // Database Name
$connection = mysqli_connect(DB_SERVER,DB_USERNAME,DB_PASSWORD,DB_DATABASE); // connecting with database
?>
Kindly have a look on it and let me know If i missed any part of code or anything wrong.
Thanks