How to get email address field using LinkedIn Javascript API?

I use the LinkedIn API JavaScript to enter the application, but the API does not return an email address, although I require permission for this particular field. I include an API script as follows:

<script type="text/javascript" src="//platform.linkedin.com/in.js"> api_key: API_KEY scope: r_fullprofile r_emailaddress </script> 

then I turn on the "Login" button in the markup:

 <script type="in/Login" data-onAuth="onLinkedInAuth"> 

and finally, I have a function to add a callback for the API response:

 function onLinkedInAuth() { var fields = ['first-name', 'last-name', 'email-address']; IN.API.Profile("me").fields(fields).result(function(data) { console.log(data); }).error(function(data) { console.log(data); }); }; 

I get only the first and last name, but the API does not return an email field.

Link: https://developer.linkedin.com/documents/profile-fields#email

+9
javascript api linkedin
source share
5 answers

1- make sure you have done email permission (r_emailaddress) in your application http://developer.linkedin.com/documents/authentication#granting

2-, then you can use this

  <script type="text/javascript" src="http://platform.linkedin.com/in.js"> api_key: key **onLoad: onLinkedInLoad** authorize: true </script> <script> function onLinkedInLoad() { IN.Event.on(IN, "auth", onLinkedInAuth); } // 2. Runs when the viewer has authenticated function onLinkedInAuth() { IN.API.Profile("me").fields("first-name", "last-name", "email-address").result(function (data) { console.log(data); }).error(function (data) { console.log(data); }); } </script> 

hope this helps you :) thanks

+14
source share

Hi @Ulises Figueroa, Maybe I will come a little late, but here is how I did it:

Start with the original script tag at the top of the page in the chapter section:

 <script> Client Id Number here: onLoad: onLinkedInLoad authorize: true </script> 

Then, in your JS file (I placed an external JS file to handle this API / Auth signature), place the following data:

 function onLinkedInLoad() { IN.Event.on(IN, "auth", getProfileData); } function onSuccess(data) { console.log(data); } function onError(error) { console.log(error); } function getProfileData(){ IN.API.Profile("me").fields(["firstName","lastName", "email-address", "positions"]).result(function(data) { var profileData = data.values[0]; var profileFName = profileData.firstName; var profileLName = profileData.lastName; if(data.values[0].positions._total == "0" || data.values[0].positions._total == 0 || data.values[0].positions._total == undefined) { console.log("Error on position details"); var profileCName = "Details Are Undefined"; } else { var profileCName = profileData.positions.values["0"].company.name; } var profileEName = profileData.emailAddress; //console.log all the variables which have the data that //has been captured through the sign up auth process and //you should get them... }); } 

Then, last but not least, add the following to your HTML DOCUMENT, which will help you initiate a popup window for the attached registration form:

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

The above setup worked for me. Of course, this will help you.

Greetings and have a nice day.

+2
source share

The implementation looks good. I believe this is the result of profile privacy settings. In related documents:

Not all fields are available for all profiles. The available fields depend on the relationship between the user you make, the name and the member, the information that the member has chosen to provide, and their privacy settings. You should not assume that anything other than id is returned for this member.

+1
source share

I realized that this only happens with some LinkedIn accounts, so this may be due to the fact that email is used in the privacy settings. I could not find links to the documentation, so I had to consider the case when the email field is not available.

-one
source share

Use this API:

  https://api.linkedin.com/v1/people/~:(id,firstName,lastName,num-connections,picture-url,emailAddress)?format=json login() { let scopes:any = ['r_basicprofile', 'r_emailaddress', 'rw_company_admin', 'w_share']; this.linkedin.login(scopes, true) .then(() => { this.linkedin.getRequest('people/~:(id,firstName,lastName,num-connections,picture-url,emailAddress)') .then(res => { this.selfData = res; }) .catch(e => { console.log(e); }); }) .catch(e => { console.log('Error logging in', e); }); } 
-one
source share

All Articles