簡體   English   中英

使用linkedin API javascript SDK獲取電子郵件地址

[英]get email address using linkedin API javascript SDK

我看到了這樣的其他討論,但是我無法弄清楚如何從linkedin API獲取電子郵件地址,我在應用程序中啟用了r_emailaddress,在這里我做了以下事情:

index.html:

    <!-- Linkedin login -->
 <script type="text/javascript" src="http://platform.linkedin.com/in.js">
    api_key: myapikey
    scope: r_basicprofile r_emailaddress
    onLoad:onLinkedInLoad
    authorize:true
    lang:en_US
 </script>  
 <script type="in/Login"></script>

這里是腳本:

    // Setup an event listener to make an API call once auth is complete
function onLinkedInLoad() {
    IN.Event.on(IN, "auth", getProfileData);
}

// Handle the successful return from the API call
function onSuccess(data) {
    console.log(data);
    $('#nome').val(data.firstName);
    $('#cognome').val(data.lastName);
    $('#email').val(data.emailAddress);             
}

// Handle an error response from the API call
function onError(error) {
    console.log(error);
}

// Use the API call wrapper to request the member's basic profile data
function getProfileData() {
    var fields = ['firstName', 'lastName', 'emailAddress'];
    IN.API.Raw("/people/~").result(onSuccess).error(onError);   
}

我想用data.emailAdress填充輸入字段,但是我沒有在對象中輸入它,有人知道該怎么辦? 謝謝!

我至少知道了!

IN.API.Raw("/people/~:(id,firstName,lastName,emailAddress)?format=json")
    .result(onSuccess)
    .error(onError);

Aya Magdy在以下“ SO問題”頁面上提供了此問題的答案:

如何使用LinkedIn Javascript API獲取電子郵件地址字段?

對於您而言,您要做的就是確保已在Linkedin應用程序頁面的“默認應用程序權限”部分中選中了“ r_emailaddress”。

然后更改您的getProfileData()函數,使其如下所示:

function getProfileData() {
   IN.API.Profile("me").fields("first-name", "last-name", "email-address").result(onSuccess).error(onError);
}

有關IN.API.Profile函數的文檔可以在這里找到:

https://developer-programs.linkedin.com/documents/inapiprofile

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM