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

后端 未结 4 1642
南笙
南笙 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:

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

    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:

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

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

    Cheers and have a nice day.

    0 讨论(0)
  • 2021-02-14 19:39

    Implementation looks good. I'd believe this is a result from the profile's privacy settings. Per linked-in's docs:

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

    0 讨论(0)
  • 2021-02-14 19:40

    1- be sure you made email permission (r_emailaddress) in your app http://developer.linkedin.com/documents/authentication#granting

    2- then you may 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 will help you :) thanks

    0 讨论(0)
  • 2021-02-14 19:50

    I figured out that this only happens with certain LinkedIn accounts, so this might be caused because some privacy setting with the email. I couldn't find any reference to the documentation so I had to consider the case when email field is not available.

    0 讨论(0)
提交回复
热议问题