2015-04-03 58 views
4

我想要集成Linkedin登錄使用javascript。 我搜索了並獲得相關結果。但很多搜索結果都表示下面的代碼:如何使用javascript登錄並使用javascript並顯示配置文件信息

<script type="in/Login"> 
</script> 

用於創建登錄按鈕。但我想用我自己的自定義按鈕並在我的HTML中的「onClick」事件上調用一個函數。 幫助正確的方向。

我的代碼:

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; 
} 

這是我的HTML片段:

<li> 
    <a href="javascript:void(0);" onClick="linkedinLogin()"> 
     <img src="images/icon_linkedIn.png" /> 
     <span>LinkedIn</span> 
    </a> 
</li> 
+0

你能分享你所嘗試過的嗎? – 2015-04-03 07:43:12

+0

@AhmedZiani我添加了代碼 – mahendrakawde 2015-04-03 07:50:11

+0

看來onLoad:OnLinkedInFrameworkLoad沒有被調用。 – mahendrakawde 2015-04-03 07:50:54

回答

0

<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>

你可以試試這個?

+0

Thanks.U保存了我的一天。 – 2017-07-26 13:58:13

+0

接受答案,如果它是正確的你。 – ABC 2018-01-04 07:21:47

相關問題