使用linkedin登录并在Angular2中获取用户信息 [英] Login with linkedin and get user information in Angular2
问题描述
我是 Angular2 的新手,我想集成链接登录功能并为我的 Angular2 项目获取当前登录的用户信息.
I am new to Angular2, I want to integrate linked login functionality and get the currently singed in user information for my Angular2 project.
我已经使用linkedin 开发者帐户创建了应用程序并且有客户ID和客户密码并尝试了下面的代码,但它给了我错误
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: 错误:您必须指定有效的 JavaScript API 域作为此密钥配置的一部分.在 ht……}
ZoneAwareError {__zone_symbol__error: Error: You must specify a valid JavaScript API Domain as part of this key's configuration. at ht……}
我尝试了两种使用双引号( api_key: "81zbsc62i53h5x" 和没有它( api_key: 81zbsc62i53h5x)声明 api 密钥的方法,但出现了同样的错误.
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.
包含在 index.html 下面的脚本
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>
app.component.ts 中的代码
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 登录按钮并点击
app.component.html login button and click
<button (click)="onLinkedInLoad()" class="linkedin-btn">LinkedIn Login</button>
非常感谢任何帮助.
推荐答案
当您尝试将linkedin sdk 与未注册的域集成时,会出现此错误.您需要做两件事:1.在linkedin应用面板中添加您的域名:链接面板
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.设置您的主机文件以在您测试域时测试您的应用程序.
2.Set your host file to test your application when you test the domain.
这篇关于使用linkedin登录并在Angular2中获取用户信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!