官方文档:https://developer.linkedin.com/docs/signin-with-linkedin
在此创建App 并获取 api_key: https://www.linkedin.com/secure/developer?newapp=
1 <script type="text/javascript" src="https://platform.linkedin.com/in.js"> 2 api_key: ********* // api_key 不可添加引号! 3 authorize: false 4 onLoad: onLinkedInLoad //必须 5 </script> 6 7 8 <script> 9 10 // 判断登录状态 11 function onLinkedInLoad() { 12 IN.Event.on(IN, "auth", getProfileData); 13 } 14 15 // 登录成功 16 function onSuccess(date) { 18 console.dir(date); 19 //用户授权登录后在此数据处理 20 } 21 22 // Handle an error response from the API call 23 function onError(error) { 24 console.log(error); 25 } 26 27 // 获取用户信息 28 function getProfileData() { 29 IN.API.Raw("/people/~:(id,email-address,firstName,lastName,pictureUrl,siteStandardProfileRequest)").result(onSuccess).error(onError); 30 } 31 32 </script>
HTML 代码中写入 <script type='in/Login'></script> 将自动生成登录按钮。
如需自定义按钮样式,方法很多,而我是这样做的:
1 <div id='linkedin' style='display:none'> 2 <script type='in/Login'></script> 3 </div> 4 5 <a class="" id='linkedin_login' >LinkedIn Login</a>
1 <script> 2 window.onload=function(){ 3 var linkedin=$('#linkedin span:first a span:first'); 4 var linkedin_login=$('#linkedin_login'); 5 linkedin_login.click(function(){ 6 linkedin.click(); 7 }) 8 } 9 </script>