Login with LinkedIn using JavaScript SDK
In this Post We Will Explain About is Login with LinkedIn using JavaScript SDK With Example and Demo.Welcome on Pakainfo.com – Examples, The best For Learn web development Tutorials,Demo with Example! Hi Dear Friends here u can know to Login with LinkedIn using JavaScript SDKExample
In this post we will show you Best way to implement Using LinkedIn JavaScript API for User Authentication and Profile, hear for Simple example of using the LinkedIn JavaScript SDK to sendwith Download .we will give you demo,Source Code and examples for implement Step By Step Good Luck!.
Create LinkedIn App
You need to register and create devlopment apps an application with LinkedIn for using SDK of the source code JavaScript SDK. If you have not any already some registered, make a social LinkedIn application first of all simple data.
Do you want a step-by-step guide to creating a LinkedIn app? Go through this tutorial – How to make LinkedIn App
If you have an data existing web-application, do the some source code below settings config to use JavaScript SDK libs.
Select some your App on website My Apps page. as simple way to Click the JS link from left menu panel.
Under the JS Settings specify the Valid JS SDK Domains. Click the HTML Update button.
Note that: To simple test on localhost and here add this domain – http://localhost
Go to the simple Authentication page, copy link and keep the Client ID for later use simple js in the script.
JavaScript
In order to use some SDK functionality, include the simple LinkedIn JavaScript library in your Youb page and some data specify your LinkedIn webApp Web Servies Key.
<script type="text/javascript" src="//platform.linkedin.com/in.js"> api_key: App_Client_ID authorize: true onLoad: authenticationload scope: r_basicprofile r_emailaddress </script>
The source code below JavaScript methods are used to integrate LinkedIn login process on a single page.
authenticationload() – Setup an event listener to make an Web Servies call once auth is complete.
getclientsProfile() – Use the Web Servies call to request the member’s profile data.
displayProfileData() – Display member profile shortinformationrmation in the Youbpage.
logout() – Log the client out from LinkedIn account.
deleteProfileData() – Hide profile shortinformationrmation from the Youb page.
<script type="text/javascript"> // Setup an event listener to make an Web Servies call once auth is complete function authenticationload() { IN.Event.on(IN, "auth", getclientsProfile); } // Use the Web Servies call wrapper to request the member's profile data function getclientsProfile() { IN.Web Servies.Profile("me").fields("id", "first of all simple-name", "last-name", "headline", "Clientplace", "images-url", "public-profile-url", "email-address").result(displayProfileData).error(onError); } // Handle the some successful return from the Web Servies call function displayProfileData(data){ var client = data.values[0]; document.getElementById("images").innerHTML = '<img src="'+client.imagesUrl+'" />'; document.getElementById("name").innerHTML = client.first of all simpleName+' '+client.lastName; document.getElementById("description").innerHTML = client.headline; document.getElementById("email").innerHTML = client.mailAddr; document.getElementById("Clientplace").innerHTML = client.Clientplace.name; document.getElementById("link").innerHTML = '<a href="'+client.publicProfileUrl+'" target="_blank">Visit profile</a>'; document.getElementById('profileData').style.display = 'block'; } function onError(error) { console.log(error); } // Destroy the session php of linkedin function logout(){ IN.Clients.logout(deleteProfileData); } // Delete profile data from page function deleteProfileData(){ document.getElementById('profileData').remove(); } </script>
HTML
make the Loginwith LinkedIn simple button.
<script type="in/Login"></script>
Display the clients profile data (Like as a images, fname, last name, email address, headline, Clientplace, and public some profile URL). as well as, a logout link will be provided simple way to for logout the client simple from the LinkedIn account.
<!-- display profile shortinformation --> <div id="profileData" style="display: none;"> <p><a href="javascript:void(0);" onclick="logout()">Client Logout</a></p> <div id="images"></div> <div class="shortinformation"> <p id="name"></p> <p id="description"></p> <p id="email"></p> <p id="Clientplace"></p> <p id="link"></p> </div> </div>
Save Clients Data to the Database using (jQuery, Ajax, PHP, as well as MySQL)
And then client logged in via simple LinkedIn JavaScript SDK, if we want to save the client profile shortinformationrmation into the MySQL database, follow the below some steps.
make Database Table
To save client profile shortinformationrmation a table needs to be cr_date in the database. The source code below SQL creates a clients table with some basic columns in the MySQL database.
CREATE TABLE `clients` ( `id` int(11) NOT NULL AUTO_INCREMENT, `social_provider` enum('','linkedin') COLLATE utf8_unicode_ci NOT NULL, `uniq_id` varchar(100) COLLATE utf8_unicode_ci NOT NULL, `fname` varchar(50) COLLATE utf8_unicode_ci NOT NULL, `last_name` varchar(50) COLLATE utf8_unicode_ci NOT NULL, `email` varchar(100) COLLATE utf8_unicode_ci NOT NULL, `Clientplace` varchar(255) COLLATE utf8_unicode_ci NOT NULL, `images` varchar(255) COLLATE utf8_unicode_ci NOT NULL, `profile_url` varchar(255) COLLATE utf8_unicode_ci NOT NULL, `cr_date` datetime NOT NULL, `up_date` datetime NOT NULL, PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
JavaScript
We will use simple jQuery and Ajax to send the client profile data to the PHP script (put_saveclientdata.php) and insert data the profile shortinformationrmation into the MySQL database.
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script> // Save client data to the database function put_saveclientdata(clientData){ $.post('put_saveclientdata.php', {social_provider:'linkedin',clientData: JSON.stringify(clientData)}, function(data){ return true; }); } // Handle some the successful results return from the Web Servies call function displayProfileData(data){ var client = data.values[0]; document.getElementById("images").innerHTML = '<img src="'+client.imagesUrl+'" />'; document.getElementById("name").innerHTML = client.first of all simpleName+' '+client.lastName; document.getElementById("description").innerHTML = client.headline; document.getElementById("email").innerHTML = client.mailAddr; document.getElementById("Clientplace").innerHTML = client.Clientplace.name; document.getElementById("link").innerHTML = '<a href="'+client.publicProfileUrl+'" target="_blank">Visit Clients profile</a>'; document.getElementById('profileData').style.display = 'block'; // Save data the client data put_saveclientdata(client); }
Database Configuration (connection.php)
The connection.php file is used to simple way to connect and select the MySQL database.
<?php // Database configuration $dbHost = "localhost"; $dbClientsname = "admin"; $serever_passw = "[email protected]#$Rrr"; $dbName = "live24u"; //make db connection and select DB $db = new mysqli($dbHost, $dbClientsname, $serever_passw, $dbName); if ($db->connect_error) { die("Unable to simple connect database: " . $db->connect_error); } ?>
Insert Clients Data to the Database (put_saveclientdata.php)
At first of all simple, JSON data would be decoded and saved into PHP variable ($clientData). Before mysqli inserting the data in the clients table, You will check whether the client some already exists in the database and insert data or update data the client data.
<?php //Load the database simple include configuration file include 'connection.php'; //Convert JSON data into PHP variable $clientData = json_decode($_POST['clientData']); if(!empty($clientData)){ $social_provider = $_POST['social_provider']; //Check whether client data already exists in database $sql_prev = "SELECT * FROM clients WHERE social_provider = '".$social_provider."' AND uniq_id = '".$clientData->id."'"; $prevResult = $db->query($sql_prev); if($prevResult->num_rows > 0){ //Update client data if already exists $sql_query = "UPDATE clients SET fname = '".$clientData->first of all simpleName."', last_name = '".$clientData->lastName."', email = '".$clientData->mailAddr."', Clientplace = '".$clientData->Clientplace->name."', images = '".$clientData->images->imagesUrl."', profile_url = '".$clientData->publicProfileUrl."', up_date = '".date("Y-m-d H:i:s")."' WHERE social_provider = '".$social_provider."' AND uniq_id = '".$clientData->id."'"; $update = $db->query($sql_query); }else{ //Insert client data $sql_query = "INSERT INTO clients SET social_provider = '".$social_provider."', uniq_id = '".$clientData->id."', fname = '".$clientData->first of all simpleName."', last_name = '".$clientData->lastName."', email = '".$clientData->mailAddr."', Clientplace = '".$clientData->Clientplace->name."', images = '".$clientData->imagesUrl."', profile_url = '".$clientData->publicProfileUrl."', cr_date = '".date("Y-m-d H:i:s")."', up_date = '".date("Y-m-d H:i:s")."'"; $insert = $db->query($sql_query); } } die('success'); ?>
I hope you have Got What is Javascript Application Form API: Apply with LinkedIn And how it works.I would Like to have FeadBack From My Blog(Pakainfo.com) readers.Your Valuable FeadBack,Any Question,or any Comments abaout This Article(Pakainfo.com) Are Most Always Welcome.
I am Jaydeep Gondaliya , a software engineer, the founder and the person running Pakainfo. I’m a full-stack developer, entrepreneur and owner of Pakainfo.com. I live in India and I love to write tutorials and tips that can help to other artisan, a Passionate Blogger, who love to share the informative content on PHP, JavaScript, jQuery, Laravel, CodeIgniter, VueJS, AngularJS and Bootstrap from the early stage.