4

I am trying to get LinkedIn Access Token after login. Login is working fine with JavaScript SDK and I'm able to receive "oauth_token" and member_id. I need access_token to verify the email address (if it is not forged on the way).

Below is my script:

<script>
function LoginWithLinkedIn() {
        IN.User.authorize(afterAuthorization); 
    }
    function afterAuthorization(response){
        debugger
        if(IN.User.isAuthorized()==true){
            getProfileData();
        }
    }
    function onSuccess(data) {
        console.log(data);
    }
    function onError(error) {
        console.log(error);
    }
    function getProfileData(r) {
        IN.API.Profile("me")
         .fields("id,firstName,lastName,email-address,picture-urls::(original),public-profile-url,location:(name)")
         .result(onSuccess)
         .error(onError);
    }
</script>

I need help getting the access_token after successful authorization. Any help is highly appreciated!

Thanks!

6
  • get access token from your account of your linkedIn ID see this Commented Aug 31, 2016 at 11:45
  • But I want to perform by using Java Script and C#. Because this redirects me to linkedin and then perform login and after then again redirect to my application. Commented Aug 31, 2016 at 11:52
  • @Panky26 Do you have other Idea Commented Aug 31, 2016 at 11:53
  • have a look on this link Commented Aug 31, 2016 at 12:00
  • I have done already this process now I want to again verify after login on server side Commented Aug 31, 2016 at 12:11

1 Answer 1

2

Hope following code will work

function LinkedInLogin() {
    IN.User.authorize(getProfileData);
}
function onSuccess(data) {
    jQuery('#hdnAccessToken').val(IN.ENV.auth.oauth_token);
    try {
        jQuery('#hdnSocialLoginType').val('in');
        jQuery('#HiddenFieldUserId').val(data.values[0].id);
        jQuery('#HiddenFieldEmail').val(data.values[0].emailAddress);
        jQuery('#HiddenFieldFirstName').val(data.values[0].firstName);
        jQuery('#HiddenFieldLastName').val(data.values[0].lastName);
        jQuery('#HiddenFieldType').val('linkedin');
        jQuery('#BtnLoginSocial').click();
    }
    catch (err) {
        alert(jQuery('#HiddenErrorMessage').val());
    }
    //console.log(data);
}
function onError(error) {
    console.log(error);
}
function getProfileData() {
    if (IN.User.isAuthorized() == true) {
        IN.API.Profile("me").fields("id,firstName,lastName,email-address").result(onSuccess).error(onError);
    }
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.