[英]How to Login with linkedin using javascript and display profile information
I want to integrate Linkedin login using javascript. 我想使用javascript集成Linkedin登录。 I searched for that and get relevant results. 我进行了搜索并获得了相关结果。 But lot of search results says that below code: 但是很多搜索结果显示以下代码:
<script type="in/Login">
</script>
is used to create sign-in button. 用于创建登录按钮。 But i want to use my own custom button and call a function on "onClick" event in my HTML. 但是我想使用自己的自定义按钮,并在HTML中的“ onClick”事件上调用函数。 Help in correct direction. 帮助方向正确。
My code : 我的代码:
function linkedinLogin(){
console.log('linkedinLogin called');
var src="http://platform.linkedin.com/in.js"
api_key: 'XXXXXXXXXXXXXXXX'
authorize: true
onLoad: OnLinkedInFrameworkLoad
}
function OnLinkedInFrameworkLoad()
{
IN.Event.on(IN, "auth", OnLinkedInAuth);
}
function OnLinkedInAuth() {
IN.API.Profile("me").result(ShowProfileData);
}
function ShowProfileData(profiles)
{
var member = profiles.values[0];
console.log(member);
var id=member.id;
var firstName=member.firstName;
var lastName=member.lastName;
var photo=member.pictureUrl;
var headline=member.headline;
//use information captured above
var str="<b>id</b> : "+id+"<br>";
str +="<b>firstName: </b>"+firstName+"<br>";
str +="<b>lastName: </b>"+lastName+"<br>";
str +="<b>photo: </b>"+photo+"<br>";
str +="<b>headline: </b>"+headline+"<br>";
str +="<input type='button' value='Logout' onclick='logout();'/>";
document.getElementById("status").innerHTML = str;
}
And this is my HTML snippet: 这是我的HTML代码段:
<li>
<a href="javascript:void(0);" onClick="linkedinLogin()">
<img src="images/icon_linkedIn.png" />
<span>LinkedIn</span>
</a>
</li>
<html> <head> <title>LinkedIn JavaScript API Hello World</title> <!-- 1. Include the LinkedIn JavaScript API and define a onLoad callback function --> <script type="text/javascript" src="https://platform.linkedin.com/in.js"> api_key: xxx onLoad: onLinkedInLoad authorize: true </script> <script type="text/javascript"> // 2. Runs when the JavaScript framework is loaded function onLinkedInLoad() { IN.Event.on(IN, "auth", onLinkedInAuth); } // 2. Runs when the viewer has authenticated function onLinkedInAuth() { IN.API.Profile("me").fields("id","first-name", "last-name", "email-address").result(displayProfiles); } // 2. Runs when the Profile() API call returns successfully function displayProfiles(profiles) { member = profiles.values[0]; document.getElementById("profiles").innerHTML = "<p>"+member.id+"<br> " + member.firstName + "<br> " + member.lastName + "<br>"+member.emailAddress+"</p>"; } </script> </head> <body> <!-- 3. Displays a button to let the viewer authenticate --> <script type="in/Login"></script> <!-- 4. Placeholder for the greeting --> <div id="profiles"></div> </body> </html>
Can you try this ? 你可以试试这个吗?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.