我正在尝试在我的Web应用程序中实现带有链接的登录。这是我的代码。
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script type="text/javascript" src="//platform.linkedin.com/in.js">
api_key: 'key here'
</script>
</head>
<body>
<script>
IN.User.authorize(function (e) {
console.log(e);
}, function (e) {
console.log(e);
});
</script>
</body>
但是它给了我错误'无法读取Object.authorize(in.js:18)中未定义的属性'then''
我也尝试过这种方式。
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script type="text/javascript" src="//platform.linkedin.com/in.js">
api_key: 'key here'
onLoad: 'onLinkedInLoad'
authorize: true
</script>
</head>
<body>
<!-- LinkedIn signin button -->
<script type="in/Login"></script>
<script type="text/javascript">
// Setup an event listener to make an API call once auth is complete
function onLinkedInLoad() {
IN.Event.on(IN, "auth", getProfileData);
}
</script>
</body>
但它给了我错误
'in.js:7未捕获(承诺)TypeError:无法实例化'login'的标记:无法读取null的属性'on' 在新版本(Login.js?version = 0.1.149:7) 在in.js:18'
答案 0 :(得分:0)
linkedIn的文档和示例显示api_key和onLoad函数未设置为字符串定界符。
api_key: 0192afsdj10
onLoad: onLinkedInLoad
第二,您尚未为getProfileData函数添加函数。
这是应该看起来像的例子。
function getProfileData() {
IN.API.Profile("me").fields("id", "first-name", "last-name", "headline", "location", "picture-url", "public-profile-url", "email-address").result(displayProfileData);
}
function displayProfileData(profiles){
var member = profiles.values[0];
console.log(member);
}
请参阅引用为here的代码