0

I am trying to get my Angular2 service to use the LinkedIN javascript SDK that is loaded by the script linkedin provides. the functionality works for getting the data and returning it but I can't set the local function variable to the data I got back from linkeidn

export class LinkedInAuthService {

constructor(

) {

}

linkedInAuthorization() {
    window['IN'].User.authorize();
    window['IN'].Event.on(window['IN'], 'auth', this.getLinkedInUserInfo);
}
getLinkedInUserInfo() {
    let linkedinInfo:any;
    window['IN']
        .API
        .Raw()
        .url("/people/~:(firstName,lastName,emailAddress,industry,specialties,positions)?format=json")
        .result(function(data:any){
            console.log(data) //logs data correctly
            linkedinInfo = data 
        });
    console.log(linkedinInfo) // undefined
}

AuthLinkedInUserforGlx() {
    console.log(localStorage.getItem('linkedinInfo'))
}
}

I think the problem is when I set linkedinInfo = data it is not setting it locally, just not sure how to make it local

pwborodich
  • 382
  • 6
  • 22

1 Answers1

0

This worked for me

export class LinkedInService {
IN = window['IN'];
userProfile: Object;
constructor() {
    this.userProfile = JSON.parse(localStorage.getItem('profile'))
    this.IN.Event.on(this.IN, 'auth', this.getLinkedInUserInfo);
    console.log('end of constructor')
}

linkedInAuthorization(){
    this.IN.User.authorize();
    console.log('end of linkedInAuthorization service')
}

getLinkedInUserInfo() {
    this.IN.API.Raw()
        .url("/people/~:(firstName,lastName,emailAddress,industry,specialties,positions)?format=json")
        .result((data:any) => {
            localStorage.setItem('profile', JSON.stringify(data));
            this.userProfile = data;
        });
    console.log('end of getLinkedInUserInfo service');
    this.AuthLinkedInOnGlx
}

AuthLinkedInOnGlx (){

}



}
pwborodich
  • 382
  • 6
  • 22