Login with linkedin and get user information in Angular2

谁都会走 提交于 2019-12-12 02:33:31

问题


I am new to Angular2, I want to integrate linked login functionality and get the currently singed in user information for my Angular2 project.

I have created App in using linkedin developer account and have Client ID and Client Secret and tried below code but it gives me error

ZoneAwareError {__zone_symbol__error: Error: You must specify a valid JavaScript API Domain as part of this key's configuration. at ht……}

I tried both the way for declaring api key using double quotes ( api_key: "81zbsc62i53h5x" and without it ( api_key: 81zbsc62i53h5x) but same error comes.

Included below script in index.html

     <script type="text/javascript" src="http://platform.linkedin.com/in.js">
    api_key: 81zbsc62i53h5x
    authorize: true
    onLoad: onLinkedInLoad
    scope: r_fullprofile
  </script>

code in app.component.ts

declare var IN: any;
export class AppComponent {
  onLinkedInLoad() {
    IN.Event.on(IN, "auth", this.onLinkedInAuth);
  }
  public onLinkedInAuth() {
    IN.API.Profile("me")
      .fields("firstName", "lastName")
      .result(this.displayProfiles)
      .error(this.displayProfilesErrors);
  }
  public displayProfiles(profiles) {
    var linkedinmember = profiles.values[0];
    console.log(JSON.stringify(linkedinmember));
    console.log(linkedinmember.firstName + " " + linkedinmember.lastName);
  }
  public displayProfilesErrors(error) {
    console.log(error.message);
    console.log(error);
  }
}

app.component.html login button and click

 <button (click)="onLinkedInLoad()" class="linkedin-btn">LinkedIn Login</button> 

Any help highly appreciated.


回答1:


This error appears when you try to integrate the linkedin sdk with unregistered domain. There are 2 things you need to do: 1.Add your domain in the linkedin app panel: Linkedin Panel

2.Set your host file to test your application when you test the domain.



来源:https://stackoverflow.com/questions/43502922/login-with-linkedin-and-get-user-information-in-angular2

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!