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

后端 未结 4 1628
南笙
南笙 2021-02-14 19:08

I\'m using the LinkedIn Javascript API to sign in users to my application, however the API is not returning the email address even though I\'m requiring permission for that spec

4条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2021-02-14 19:38

    Hello there @Ulises Figueroa, May be I am coming in a bit late but this is how I had got this done:

    Start off with the initial script tag on the top of your page within the head section:

    
    

    Then, in your JS File,(I had placed an external JS File to process this API sign up/ Auth), have the following details placed:

    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 the least, add the following in your HTML DOCUMENT which can help you initiate the window popup for the linkedin auth sign up form:

    
    

    The above setup had worked for me. Sure this will help you out.

    Cheers and have a nice day.

提交回复
热议问题