简体   繁体   English

如何使用javascript登录linkedin并显示个人资料信息

[英]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.

相关问题 如果我们具有该用户的个人资料ID,则如何使用LinkedIn Javascript API获取其他用户的个人资料详细信息 - How to fetch profile details of another user using LinkedIn Javascript API, if we have profile id of that user 如何使用linkedin API获取linkedin上的个人资料的网址 - How can I get the url of a profile on linkedin using the linkedin API 如何使用 JavaScript 显示用户输入的信息? - How to display user entered information using JavaScript? 使用JavaScript和REST API检索LinkedIn个人资料图片 - Retrieve LinkedIn Profile Picture Using JavaScript with REST API 使用JavaScript API从LinkedIn获得个人资料详细信息 - Geting Profile Details from LinkedIn using JavaScript API Linkedin Javascript Profile API损坏 - Linkedin Javascript Profile API broken 如何通过Javascript API检索linkedin用户的完整资料 - How to retrieve full profile of linkedin user via Javascript API 如何以模式显示用户个人资料信息? - How to display user profile information in a modal? 使用NodeJS和express登录成功后如何显示用户信息 - How to display user information after successful login using NodeJS and express 如何使用来自另一个站点的登录信息发出 javascript 请求 - how to make javascript requests using login information from another site
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM