使用 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 填充输入字段,但对象中没有它,有人知道该怎么做吗?谢谢!

Aya Magdy 在以下 SO 问题页面上提供了此问题的答案:

How do I get email address field using the LinkedIn Javascript API?

在您的情况下,您所要做的就是确保您在 Linkedin 应用程序页面的 'Default Application Permissions' 部分中检查了 '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

我至少明白了!

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