用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开发人员帐户创建了App,并且具有客户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应用程序面板中添加您的域: 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屋!