加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

如何在Angular2中集成Linkedin

发布时间:2020-12-17 07:14:54 所属栏目:安全 来源:网络整理
导读:我在Angular2中的LinkedIn身份验证方面遇到问题我的代码是. import {Component,OnInit,NgZone} from 'angular2/core';import {HTTP_PROVIDERS} from 'angular2/http';import {ROUTER_DIRECTIVES,Router} from 'angular2/router';declare var IN : any;@Compo
我在Angular2中的LinkedIn身份验证方面遇到问题我的代码是.

import {Component,OnInit,NgZone} from 'angular2/core';
import {HTTP_PROVIDERS} from 'angular2/http';
import {ROUTER_DIRECTIVES,Router} from 'angular2/router';

declare var IN : any;

@Component({
  directives : [ROUTER_DIRECTIVES],selector : '.main',providers : [HTTP_PROVIDERS],templateUrl : './app/registration/employee.reg.html'
})

export class EmployeeRegistrationComponent implements OnInit{

 constructor(private zone : NgZone){
    this.zone.run(() => {
        $.proxy(this.OnLinkedInFrameworkLoad,this);
    });
}

ngOnInit(){
    var linkedIn = document.createElement("script");
    linkedIn.type = "text/javascript";
    linkedIn.src = "http://platform.linkedin.com/in.js";
    linkedIn.innerHTML = "n"+
        "api_key: **********n" +
        "authorize: truen" +
        "onLoad:" + this.OnLinkedInFrameworkLoad ;
    document.head.appendChild(linkedIn);

    var script = document.createElement("script");
    script.type = "in/Login";
    document.body.appendChild(script);
}

OnLinkedInFrameworkLoad = () => {
    IN.Event.on(IN,"auth",this.OnLinkedInAuth);
}

OnLinkedInAuth = () => {
    IN.API.Profile("me").result(result => this.ShowProfileData);
}

ShowProfileData(profiles) {
    console.log(profiles);
    var member = profiles.values[0];
    var id=member.id;
    var firstName=member.firstName;
    var lastName=member.lastName;
    var photo=member.pictureUrl;
    var headline=member.headline;

    //use information captured above
   }

}

控制台投掷错误:angular2-polyfills.js:1250未捕获错误:无法执行’function(){‘.请提供有效的回拨功能.

请帮我解决我做错了什么…

解决方法

我通过检查第一个脚本标记中的源代码输出找到了问题.

问题出在你放的地方:

"onLoad:" + this.OnLinkedInFrameworkLoad;

它将输出为:

onLoad: function () {?            IN.Event.on(IN,_this.OnLinkedInAuth);?        }

就像它在官方开发者文档中所说的那样

Important!

The line breaks between the arguments within the tags are important since there is no other form of field separator. If you are using a templating language or code minifier that strips whitespace from your rendered HTML,be aware that you will need to make an exception to preserve the line-breaks within this tag,otherwise they will not be parsed properly.

资料来源:https://developer.linkedin.com/docs/getting-started-js-sdk

我还没有找到如何解决Angular 2的LinkedIn登录问题,但我会再次尝试其他解决方案

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读