How to use linkedin login api in my php website?

If you want linkedin login api for your php website and use registration with linkedin then you came on right post.
here is some code for your linkedin login follow the instruction as in this post and then You can easily apply this linkedin login in your website

add this code in your header

Make a linkedin image the name of that image should be linkedin.jpg and place this in your images folder this image will show on linekedin button



<script language="javascript" type="text/javascript" src="/js/confirmed_custom.js" ></script>
<script type="text/javascript" src="http://platform.linkedin.com/in.js">
  api_key: your website likedin api        // HGYbaYgas6Hfa&
  onLoad: onLinkedInLoad
  authorize: false
</script>
<script type="text/javascript">
function onLinkedInLoad() {
$('a[id*=li_ui_li_gen_]') .css({marginBottom:'20px'}) .html('<img src="images/linkedin.jpg" border="0" />');

  IN.Event.on(IN, "auth", function() {onLinkedInLogin();});
  IN.Event.on(IN, "logout", function() {onLinkedInLogout();});
}
</script>
<?php if(isset($_SERVER['HTTP_REFERER']))
{?>
    <input type="hidden" name="in_last_url" id="in_last_url"  value="<?=$_SERVER['HTTP_REFERER'];?>"/>
<?php }
else
{?>
<input type="hidden" name="in_last_url" id="in_last_url"  value="base_url"/>
<?php }
?>
   <input type="hidden" name="in_base_url" id="in_base_url"  value="base_url"/>

note: replace  value="base_url" in hidden field with your site url

Now make a new file which name will be confirmed_custom.js and paste this code in this file which is below this line

// JavaScript Document
function onLinkedInLogin() {
var baseurl = $('#in_base_url').val();
var lasturl = $('#in_last_url').val();

IN.API.Profile("me").fields(["id","firstName","lastName","headline","industry","location","date-of-birth","pictureUrl","positions","phone-numbers","siteStandardProfileRequest","educations","summary","specialties","public-profile-url"]).result(function resp(profiles){
                                                                                                                                                                                                                                                                 //alert(JSON.stringify(profiles));
var pno = '';
var pos='';
var con='';


if(typeof(profiles.values[0].phoneNumbers.values) !="undefined"){
        var phonenumber = profiles.values[0].phoneNumbers.values;
        var phonelength = phonenumber.length;
        var pno = phonenumber[0].phoneNumber;
}

if(typeof(profiles.values[0].positions) !="undefined"){
    if(typeof(profiles.values[0].positions.values) !="undefined"){
            var pos = profiles.values[0].positions.values;
            var con = pos.length;
            var prevcompany= new Array(5);
            var companyposition= new Array(5)
            var j=0;
            for(var i=0; i< con ; i++){
                if(typeof(pos[i].isCurrent) !="undefined"){
                            var abc= pos[i].isCurrent;
                }
               if(abc == true){
                    if(typeof(pos[i].company.name) !="undefined"){
                    var presentcompany= pos[i].company.name;}
                    if(typeof(pos[i].title) !="undefined"){
                    var presentposition= pos[i].title;}
               }else{
                    if(typeof(pos[i].company.name) !="undefined"){
                    prevcompany[j]= pos[i].company.name;}
                    if(typeof(pos[i].title) !="undefined"){
                    companyposition[j]= pos[i].title;}
                    j++;
               } 
         }
    }
}
var month='';
var day='';
var year='';
var name='';
var code='';
var pos1='';
var summary='';
var specialties='';
var edu='';
var dgre='';
var school='';
 //alert(JSON.stringify(profiles.values[0].educations));
if(typeof(profiles.values[0].educations) !="undefined"){
    if(typeof(profiles.values[0].educations.values) !="undefined"){
            if(typeof(profiles.values[0].educations.values[0].fieldOfStudy) !="undefined"){
                    var edu = profiles.values[0].educations.values[0].fieldOfStudy;
            }
            if(typeof(profiles.values[0].educations.values[0].degree) !="undefined"){
                    var dgre = profiles.values[0].educations.values[0].degree;
            }
            if(typeof(profiles.values[0].educations.values[0].schoolName) !="undefined"){
                var school = profiles.values[0].educations.values[0].schoolName;
            }
    }
}

if(typeof(profiles.values[0].summary) !="undefined"){
    var summary = profiles.values[0].summary;
}
if(typeof(profiles.values[0].specialties) !="undefined"){
    var specialties = profiles.values[0].specialties;
}

if(profiles.values[0].phoneNumbers._total !=0){
     pos1=profiles.values[0].phoneNumbers.values[0].phoneNumber;
}
if(typeof(profiles.values[0].pictureUrl)=="undefined"){
     profiles.values[0].pictureUrl='';
}
if(typeof(profiles.values[0].dateOfBirth) !="undefined"){
    if(typeof(profiles.values[0].dateOfBirth.month) !="undefined"){
        var month  =profiles.values[0].dateOfBirth.month;
    }
    if(typeof(profiles.values[0].dateOfBirth.day) !="undefined"){
        var day  =profiles.values[0].dateOfBirth.day;
    }
    if(typeof(profiles.values[0].dateOfBirth.year) !="undefined"){
        var year  =profiles.values[0].dateOfBirth.year;
    }
}
if(typeof(profiles.values[0].industry)=="undefined"){
     profiles.values[0].industry='';
}
if(typeof(profiles.values[0].location) !="undefined"){
    if(typeof(profiles.values[0].location.name) !="undefined"){
        var name    =profiles.values[0].location.name;
    }
    if(typeof(profiles.values[0].location.country) !="undefined"){
        if(typeof(profiles.values[0].location.country.code) !="undefined"){
            var code    =profiles.values[0].location.country.code;
        }
    }
}
if(typeof(profiles.values[0].headline)=="undefined"){
 profiles.values[0].headline='';
}
if(typeof(profiles.values[0].lastName)=="undefined"){
 profiles.values[0].lastName='';
}
var allinall= new Array();
allinall[0]=profiles.values[0].firstName;
allinall[1]=profiles.values[0].lastName;
allinall[2]=profiles.values[0].industry;
allinall[3]=code;
allinall[4]=name;
allinall[5]=profiles.values[0].pictureUrl;
allinall[6]=profiles.values[0].headline;
allinall[7]= month;
allinall[8]=year;
allinall[9]=day;
allinall[10]=presentcompany;
allinall[11]=pos1;
allinall[12]= profiles.values[0].publicProfileUrl;
allinall[13]= profiles.values[0].id;
allinall[14]= prevcompany;
allinall[15]= companyposition;
allinall[16]= presentposition;
allinall[17]= edu;
allinall[18]= dgre;
allinall[19]= school;
allinall[20]= summary;
allinall[21]= month;
allinall[22]= pno;

//alert(JSON.stringify(allinall));


$.post(baseurl+"signup.php", {'allinall[]' : allinall},function(data){
if(data!='')
{
  
alert(data); // this will show the data of return by you of signup.php page
}
});

});
}


now data of linkedin will transfer on signup.php in array form u can save the as you want according to your need.
Or for more help You can make signup.php and paste this code on this file which is below this line

if(!empty($_REQUEST['allinall'])){
                    $allinall =$_REQUEST['allinall'];
                    $id= $allinall[13];
                    $headline = addslashes($allinall[6]);
                    $profileurl = $allinall[12];
                    $profileurl = mysql_escape_string($profileurl);
                    $positions= addslashes($allinall[10]);
                    $pno      = $allinall[11];
                    $firstname= $allinall[0];
                    $lastname= $allinall[1];
                    $imagepath = $allinall[5];
                    $industry= addslashes($allinall[2]);
                    $countrycode= $allinall[3];
                    $locationname= addslashes($allinall[4]);
                    $dateOfBirthday   = $allinall[9];
                    $dateOfBirthmonth = $allinall[7];
                    $dateOfBirthyear  = $allinall[8];
                    $position = addslashes($allinall[16]);
                    $dateofbirth = NULL;
                    $prevcom= $allinall[14];
                    $prevpos= $allinall[15];
                    $edu= addslashes($allinall[17]);
                    $dgre = addslashes($allinall[18]);
                    $school1= addslashes($allinall[19]);
                    $summary1= addslashes($allinall[20]);
                    $nothing = $allinall[22];
                    $phoneno = $allinall[22];
                   
        }
   
        if($dateOfBirthday != "null"){
                    $dob              =$dateOfBirthyear."-".$dateOfBirthmonth."-".$dateOfBirthday;
                    //$dateofbirth      = date("Y-m-d",strtotime($dob));
                }

now can use variable like this in your sql query
please forgive give for my bad english....


 

Comments